Script for easily configuring, using, switching and comparing local offline coding models
at main 29 lines 881 B view raw
1import { execSync } from "node:child_process"; 2import { log } from "../log.js"; 3import { runPassthrough } from "../util.js"; 4import { getActiveChatModel, getActiveAutocompleteModel } from "../runtime-config.js"; 5import type { ModelDef } from "../registry/models.js"; 6 7function isPulled(ollamaTag: string): boolean { 8 try { 9 const output = execSync("ollama list", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }); 10 return output.includes(ollamaTag); 11 } catch { 12 return false; 13 } 14} 15 16function pullModel(model: ModelDef): void { 17 if (isPulled(model.ollamaTag)) { 18 log(`Model already pulled: ${model.ollamaTag}`); 19 return; 20 } 21 22 log(`Pulling ${model.name} (${model.ollamaTag})...`); 23 runPassthrough(`ollama pull ${model.ollamaTag}`); 24} 25 26export function downloadModels(): void { 27 pullModel(getActiveChatModel()); 28 pullModel(getActiveAutocompleteModel()); 29}