zignet
Version:
MCP server for Zig — AI-powered code analysis, validation, and documentation with fine-tuned LLM
85 lines (83 loc) • 2.77 kB
JavaScript
import { o as MODEL_PATH } from "./config-BtEBjBiA.js";
import { dirname } from "node:path";
import { mkdir, unlink } from "node:fs/promises";
import { createWriteStream, existsSync } from "node:fs";
import { Readable } from "node:stream";
//#region src/llm/model-downloader.ts
const MODEL_REPO = "fulgidus/zignet-qwen2.5-coder-7b";
const MODEL_FILE = "gguf/zignet-qwen-7b-q4km.gguf";
const MODEL_SIZE_MB = 4400;
var ModelDownloader = class {
modelPath;
constructor() {
this.modelPath = MODEL_PATH;
}
/**
* Get the path to the model file
*/
getModelPath() {
return this.modelPath;
}
/**
* Check if model is already downloaded
*/
isModelAvailable() {
return existsSync(this.modelPath);
}
/**
* Download the GGUF model from HuggingFace
*/
async downloadModel(onProgress) {
if (this.isModelAvailable()) {
console.log("✅ Model already downloaded:", this.modelPath);
return;
}
console.log("📥 Downloading ZigNet model from HuggingFace...");
console.log(`📦 Size: ${MODEL_SIZE_MB}MB`);
console.log(`📍 Repo: ${MODEL_REPO}`);
await mkdir(dirname(this.modelPath), { recursive: true });
const url = `https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILE}`;
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`Failed to download model: ${response.statusText}`);
const totalBytes = parseInt(response.headers.get("content-length") || "0", 10);
if (!response.body) throw new Error("Response body is null");
const fileStream = createWriteStream(this.modelPath);
let downloadedBytes = 0;
const nodeStream = Readable.fromWeb(response.body);
nodeStream.on("data", (chunk) => {
downloadedBytes += chunk.length;
if (onProgress && totalBytes > 0) onProgress({
downloaded: downloadedBytes,
total: totalBytes,
percent: downloadedBytes / totalBytes * 100
});
});
await new Promise((resolve, reject) => {
nodeStream.pipe(fileStream);
nodeStream.on("error", reject);
fileStream.on("error", reject);
fileStream.on("finish", resolve);
});
console.log("✅ Model downloaded successfully!");
console.log(`📁 Location: ${this.modelPath}`);
} catch (error) {
if (existsSync(this.modelPath)) await unlink(this.modelPath);
throw new Error(`Failed to download model: ${error instanceof Error ? error.message : String(error)}`);
}
}
/**
* Ensure model is downloaded, download if needed
*/
async ensureModel(onProgress) {
if (!this.isModelAvailable()) await this.downloadModel(onProgress);
return this.modelPath;
}
};
/**
* Singleton instance
*/
const modelDownloader = new ModelDownloader();
//#endregion
export { modelDownloader as n, ModelDownloader as t };
//# sourceMappingURL=model-downloader-DNbIj9xs.js.map