import { existsSync } from 'node:fs'; import { basename, dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { compilePackage, defaultOptions } from './compile.ts'; const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..'); const args = process.argv.slice(2); const get = (flag: string): string | undefined => { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; }; const profile = get('--profile') ?? 'q8_0'; const options = defaultOptions(projectRoot); if (profile === 'bf16') { options.gguf = join(projectRoot, 'model-src/gguf/botpsy-0.8b-bf16.gguf'); options.out = join(projectRoot, 'artifacts/botpsy-0.8b-bf16'); options.expectedSha256 = 'a7f6b3b4e5c0c15e8b3caaf7b3814596c6d79251ca047f874d9a682e9a5127e8'; options.modelId = 'qvac/BotPsy-0.8B / BF16 reference'; } else if (profile === 'q4_k_m') { options.gguf = join(projectRoot, 'model-src/gguf/botpsy-0.8b-q4_k_m-imat.gguf'); options.out = join(projectRoot, 'artifacts/botpsy-0.8b-q4_k_m'); options.expectedSha256 = '482db2dfdbc8ab7db3d3216fd8ef071d7381dd8547aff9933bc03312839d4d83'; options.modelId = 'qvac/BotPsy-0.8B / Q4_K_M-iMat'; } else if (profile !== 'q8_0') { throw new Error(`unknown profile ${profile}`); } options.gguf = get('--gguf') ?? options.gguf; options.out = get('--out') ?? options.out; options.expectedSha256 = get('--expected-sha') ?? options.expectedSha256; for (const path of [options.gguf, options.config, options.tokenizer, options.template, options.processor, options.license, options.attributions, options.readme]) { if (!existsSync(path)) throw new Error(`missing model source file ${basename(path)}`); } const result = compilePackage(options); console.log( JSON.stringify( { profile, out: options.out, tensors: result.manifest.tensors.length, shards: result.manifest.shards.length, bytes: result.manifest.shards.reduce((sum, shard) => sum + shard.byteLength, 0), tokenizer: result.manifest.source.tokenizerSha256, template: result.manifest.source.templateSha256, }, null, 2, ), );