MCPcopy Create free account
hub / github.com/continuedev/continue / getRemoteModelInfo

Function getRemoteModelInfo

core/util/ollamaHelper.ts:54–97  ·  view source on GitHub ↗
(
  modelId: string,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

52}
53
54export async function getRemoteModelInfo(
55 modelId: string,
56 signal?: AbortSignal,
57): Promise<ModelInfo | undefined> {
58 const start = Date.now();
59 const [modelName, tag = "latest"] = modelId.split(":");
60 const url = `https://registry.ollama.ai/v2/library/${modelName}/manifests/${tag}`;
61 try {
62 const sig = signal ? signal : AbortSignal.timeout(3000);
63 const response = await fetch(url, { signal: sig });
64
65 if (!response.ok) {
66 throw new Error(`Failed to fetch the model page: ${response.statusText}`);
67 }
68
69 // First, read the response body as an ArrayBuffer to compute the digest
70 const buffer = await response.arrayBuffer();
71 const digest = getDigest(buffer);
72
73 // Then, decode the ArrayBuffer into a string and parse it as JSON
74 const text = new TextDecoder().decode(buffer);
75 const manifest = JSON.parse(text) as {
76 config: { size: number };
77 layers: { size: number }[];
78 };
79 const modelSize =
80 manifest.config.size +
81 manifest.layers.reduce((sum, layer) => sum + layer.size, 0);
82
83 const data: ModelInfo = {
84 id: modelId,
85 size: modelSize,
86 digest,
87 };
88 // Cache the successful result
89 return data;
90 } catch (error) {
91 console.error(`Error fetching or parsing model info: ${error}`);
92 } finally {
93 const elapsed = Date.now() - start;
94 console.log(`Fetched remote information for ${modelId} in ${elapsed} ms`);
95 }
96 return undefined;
97}
98
99function getDigest(buffer: ArrayBuffer): string {
100 const hash = crypto.createHash("sha256");

Callers 1

installModelMethod · 0.85

Calls 5

getDigestFunction · 0.85
errorMethod · 0.80
decodeMethod · 0.65
logMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected