Skip to content

Commit ed2fc42

Browse files
steipeteYigtwxx
andcommitted
fix(ollama): retain incompletely advertised remote models
Co-authored-by: Yigtwxx <[email protected]>
1 parent d4be129 commit ed2fc42

3 files changed

Lines changed: 214 additions & 26 deletions

File tree

‎extensions/ollama/src/provider-models.test.ts‎

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
buildOllamaProvider,
1212
buildOllamaModelDefinition,
1313
capLocalOllamaProviderContext,
14+
enrichOllamaCompletionModels,
1415
enrichOllamaModelsWithContext,
1516
fetchLoadedOllamaModelNames,
1617
isOllamaCloudModel,
@@ -269,6 +270,113 @@ describe("ollama provider models", () => {
269270
});
270271
});
271272

273+
it.each([
274+
{
275+
description: "remote host metadata",
276+
listed: {
277+
name: "deepseek-r1:671b",
278+
remote_host: "https://ollama.example",
279+
capabilities: ["vision"],
280+
},
281+
reasoning: true,
282+
},
283+
{
284+
description: "upstream remote-model-only metadata",
285+
listed: {
286+
name: "remote-chat:latest",
287+
remote_model: "upstream-chat:latest",
288+
capabilities: ["vision"],
289+
},
290+
reasoning: false,
291+
},
292+
{
293+
description: "the existing explicit cloud model contract",
294+
listed: { name: "remote-chat:cloud", capabilities: ["vision"] },
295+
reasoning: false,
296+
},
297+
])(
298+
"keeps incomplete cloud metadata discoverable with $description",
299+
async ({ listed, reasoning }) => {
300+
vi.stubGlobal(
301+
"fetch",
302+
vi.fn(async (input: string | URL | Request) =>
303+
requestUrl(input).endsWith("/api/tags")
304+
? jsonResponse({ models: [listed] })
305+
: jsonResponse({}),
306+
),
307+
);
308+
309+
await expect(buildOllamaProvider("http://127.0.0.1:11434")).resolves.toMatchObject({
310+
models: [
311+
{
312+
id: listed.name,
313+
input: ["text", "image"],
314+
reasoning,
315+
compat: { supportsTools: true },
316+
},
317+
],
318+
});
319+
},
320+
);
321+
322+
it.each([
323+
{
324+
description: "an explicitly empty inspection result",
325+
listed: {
326+
name: "remote-chat:cloud",
327+
remote_model: "upstream-chat",
328+
capabilities: ["completion", "tools"],
329+
},
330+
inspected: { capabilities: [] },
331+
},
332+
{
333+
description: "an advertised remote embedding model",
334+
listed: {
335+
name: "remote-embedding:latest",
336+
remote_model: "upstream-embedding",
337+
capabilities: ["embedding"],
338+
},
339+
},
340+
{
341+
description: "an advertised local embedding model",
342+
listed: { name: "local-embedding:latest", capabilities: ["embedding"] },
343+
},
344+
])("does not expose $description as a completion model", async ({ listed, inspected = {} }) => {
345+
vi.stubGlobal(
346+
"fetch",
347+
vi.fn(async (input: string | URL | Request) =>
348+
requestUrl(input).endsWith("/api/tags")
349+
? jsonResponse({ models: [listed] })
350+
: jsonResponse(inspected),
351+
),
352+
);
353+
354+
await expect(buildOllamaProvider("http://127.0.0.1:11434")).resolves.toMatchObject({
355+
models: [],
356+
});
357+
});
358+
359+
it("keeps strict node discovery closed when remote completion is only inferred", async () => {
360+
vi.stubGlobal(
361+
"fetch",
362+
vi.fn(async () => jsonResponse({})),
363+
);
364+
365+
await expect(
366+
enrichOllamaCompletionModels(
367+
"http://127.0.0.1:11434",
368+
[
369+
{
370+
name: "remote-chat:latest",
371+
remote_model: "upstream-chat:latest",
372+
capabilities: ["tools"],
373+
},
374+
],
375+
{ requireCompletionCapability: true },
376+
),
377+
).resolves.toEqual([]);
378+
});
379+
272380
it("forwards remote auth to model listing and show probes", async () => {
273381
const fetchMock = vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
274382
expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer cloud-key");
@@ -878,7 +986,30 @@ describe("ollama provider models", () => {
878986
},
879987
expected: { contextWindow: 32_768, supportsTools: true },
880988
},
881-
])("$description", async ({ listed, expected }) => {
989+
{
990+
description: "preserves remote-model-only list capabilities after a live inspection failure",
991+
listed: {
992+
name: "remote-chat:latest",
993+
remote_model: "upstream-chat:latest",
994+
digest: "sha256:remote-model-list-metadata",
995+
details: { context_length: 32_768 },
996+
capabilities: ["tools"],
997+
},
998+
expected: { contextWindow: 32_768, supportsTools: true },
999+
},
1000+
{
1001+
description: "preserves remote-model-only metadata after a live incomplete inspection",
1002+
listed: {
1003+
name: "remote-incomplete:latest",
1004+
remote_model: "upstream-incomplete:latest",
1005+
digest: "sha256:remote-model-incomplete-inspection",
1006+
details: { context_length: 32_768 },
1007+
capabilities: ["vision"],
1008+
},
1009+
showFailed: false,
1010+
expected: { contextWindow: 32_768, supportsTools: true },
1011+
},
1012+
])("$description", async ({ listed, expected, showFailed = true }) => {
8821013
const server = createServer((request, response) => {
8831014
response.setHeader("Content-Type", "application/json");
8841015
if (request.url === "/api/tags") {
@@ -890,8 +1021,8 @@ describe("ollama provider models", () => {
8901021
return;
8911022
}
8921023
if (request.url === "/api/show") {
893-
response.statusCode = 500;
894-
response.end(JSON.stringify({ error: "show failed" }));
1024+
response.statusCode = showFailed ? 500 : 200;
1025+
response.end(JSON.stringify(showFailed ? { error: "show failed" } : {}));
8951026
return;
8961027
}
8971028
response.statusCode = 404;

‎extensions/ollama/src/provider-models.ts‎

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type OllamaTagModel = {
2525
size?: number;
2626
digest?: string;
2727
remote_host?: string;
28+
remote_model?: string;
2829
capabilities?: string[];
2930
details?: {
3031
context_length?: number;
@@ -45,7 +46,8 @@ type OllamaRunningModel = {
4546

4647
type OllamaModelRow = OllamaTagModel | OllamaRunningModel;
4748

48-
export type OllamaModelWithContext = OllamaTagModel & OllamaModelShowInfo;
49+
export type OllamaModelWithContext = OllamaTagModel &
50+
OllamaModelShowInfo & { capabilitiesFromList?: boolean };
4951

5052
const OLLAMA_SHOW_CONCURRENCY = 8;
5153
const OLLAMA_CONTEXT_ENRICH_LIMIT = 200;
@@ -96,12 +98,27 @@ export type OllamaModelShowInfo = {
9698
export const mergeOllamaModelShowInfo = (
9799
model: OllamaModelWithContext,
98100
info: OllamaModelShowInfo,
99-
): OllamaModelWithContext => ({
100-
...model,
101-
...info,
102-
contextWindow: info.contextWindow ?? model.contextWindow ?? model.details?.context_length,
103-
capabilities: info.capabilities ?? model.capabilities,
104-
});
101+
): OllamaModelWithContext => {
102+
const incomplete =
103+
info.capabilities === undefined &&
104+
model.capabilities !== undefined &&
105+
Boolean(model.remote_host || model.remote_model || isOllamaCloudModel(model.name));
106+
return {
107+
...model,
108+
...info,
109+
contextWindow: info.contextWindow ?? model.contextWindow ?? model.details?.context_length,
110+
capabilities: incomplete
111+
? [
112+
...new Set([
113+
...(model.capabilities ?? []),
114+
...(info.showInspectionFailed ? [] : ["tools"]),
115+
...(isReasoningModelHeuristic(model.name) ? ["thinking"] : []),
116+
]),
117+
]
118+
: (info.capabilities ?? model.capabilities),
119+
...(incomplete ? { capabilitiesFromList: true } : {}),
120+
};
121+
};
105122

106123
const OLLAMA_FAILED_SHOW_INFO: OllamaModelShowInfo = Object.freeze({
107124
showInspectionFailed: true,
@@ -333,7 +350,12 @@ export async function enrichOllamaCompletionModels(
333350
);
334351
for (const model of batch) {
335352
const canComplete = model.capabilities?.includes("completion");
336-
if (!canComplete && (opts?.requireCompletionCapability || model.capabilities)) {
353+
if (
354+
!canComplete &&
355+
(opts?.requireCompletionCapability ||
356+
model.capabilities?.includes("embedding") ||
357+
(model.capabilities && !model.capabilitiesFromList))
358+
) {
337359
continue;
338360
}
339361
completionModels.push(model);
@@ -371,30 +393,26 @@ export function buildOllamaModelDefinition(
371393
capabilities?: string[],
372394
opts?: { showInspectionFailed?: boolean },
373395
): ModelDefinitionConfig {
374-
const hasVision = capabilities?.includes("vision") ?? false;
375-
const input: ("text" | "image")[] = hasVision ? ["text", "image"] : ["text"];
376-
const reasoning =
377-
supportsOllamaCloudFullThinkingEffort(modelId) ||
378-
(capabilities === undefined
379-
? isReasoningModelHeuristic(modelId)
380-
: capabilities.includes("thinking"));
381-
const compat = {
382-
supportsTools: capabilities?.includes("tools") ?? opts?.showInspectionFailed !== true,
383-
supportsUsageInStreaming: true,
384-
supportsJsonSchemaResponseFormat: !isOllamaCloudModel(modelId),
385-
};
386396
return {
387397
id: modelId,
388398
name: modelId,
389-
reasoning,
390-
input,
399+
reasoning:
400+
supportsOllamaCloudFullThinkingEffort(modelId) ||
401+
(capabilities === undefined
402+
? isReasoningModelHeuristic(modelId)
403+
: capabilities.includes("thinking")),
404+
input: capabilities?.includes("vision") ? ["text", "image"] : ["text"],
391405
cost: OLLAMA_DEFAULT_COST,
392406
contextWindow:
393407
contextWindow ??
394408
resolveOllamaCloudDefaultModel(modelId)?.contextWindow ??
395409
OLLAMA_DEFAULT_CONTEXT_WINDOW,
396410
maxTokens: OLLAMA_DEFAULT_MAX_TOKENS,
397-
compat,
411+
compat: {
412+
supportsTools: capabilities?.includes("tools") ?? opts?.showInspectionFailed !== true,
413+
supportsUsageInStreaming: true,
414+
supportsJsonSchemaResponseFormat: !isOllamaCloudModel(modelId),
415+
},
398416
};
399417
}
400418

‎extensions/ollama/src/setup-model-selection.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,45 @@ describe("Ollama onboarding model selection", () => {
206206
},
207207
);
208208

209+
it("preserves incomplete remote-model-only capabilities during interactive setup", async () => {
210+
vi.stubGlobal(
211+
"fetch",
212+
vi.fn(async (input: string | URL | Request) =>
213+
requestUrl(input).endsWith("/api/tags")
214+
? Response.json({
215+
models: [
216+
{
217+
name: "deepseek-r1:remote",
218+
remote_model: "upstream-deepseek-r1",
219+
size: 2_000_000_000,
220+
details: { context_length: 32_768 },
221+
capabilities: ["tools"],
222+
},
223+
],
224+
})
225+
: Response.json({}),
226+
),
227+
);
228+
const prompter = {
229+
select: vi.fn().mockResolvedValueOnce("local-only"),
230+
text: vi.fn().mockResolvedValueOnce("http://127.0.0.1:11434"),
231+
note: vi.fn(async () => undefined),
232+
confirm: vi.fn().mockResolvedValue(false),
233+
} as unknown as WizardPrompter;
234+
235+
const result = await promptAndConfigureOllama({ cfg: {}, prompter });
236+
237+
expect(result.defaultModel).toBe("ollama/deepseek-r1:remote");
238+
expect(result.config.models?.providers?.ollama?.models).toContainEqual(
239+
expect.objectContaining({
240+
id: "deepseek-r1:remote",
241+
contextWindow: 32_768,
242+
reasoning: true,
243+
compat: expect.objectContaining({ supportsTools: true }),
244+
}),
245+
);
246+
});
247+
209248
it("aborts pending model discovery with the setup signal", async () => {
210249
const controller = new AbortController();
211250
vi.stubGlobal(

0 commit comments

Comments
 (0)