Skip to content

Commit 772f6a3

Browse files
authored
fix(deepinfra): preserve manifest reasoning during live discovery (#129998)
1 parent de8a33a commit 772f6a3

2 files changed

Lines changed: 91 additions & 10 deletions

File tree

‎extensions/deepinfra/provider-models.test.ts‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,89 @@ describe("discoverDeepInfraModels (chat-only shim)", () => {
263263
});
264264
});
265265

266+
it("preserves bundled reasoning and compat while keeping live model facts authoritative", async () => {
267+
const rows = [
268+
makeAgentModelEntry({
269+
id: "deepseek-ai/DeepSeek-V4-Pro",
270+
metadata: {
271+
context_length: 96000,
272+
max_tokens: 4096,
273+
pricing: { input_tokens: 4, output_tokens: 8, cache_read_tokens: 0.4 },
274+
tags: ["chat"],
275+
},
276+
}),
277+
makeAgentModelEntry({
278+
id: "stepfun-ai/Step-3.7-Flash",
279+
metadata: {
280+
context_length: 192000,
281+
max_tokens: 16384,
282+
pricing: { input_tokens: 0.2, output_tokens: 1.15 },
283+
tags: ["chat", "vlm", "vision"],
284+
},
285+
}),
286+
makeAgentModelEntry({
287+
id: "deepseek-ai/DeepSeek-V3.2",
288+
metadata: {
289+
context_length: 64000,
290+
max_tokens: 8192,
291+
pricing: { input_tokens: 1, output_tokens: 2 },
292+
tags: ["chat", "reasoning"],
293+
},
294+
}),
295+
makeAgentModelEntry({
296+
id: "unlisted/no-reasoning",
297+
metadata: { context_length: 32000, max_tokens: 2048, pricing: {}, tags: ["chat"] },
298+
}),
299+
makeAgentModelEntry({
300+
id: "unlisted/with-reasoning",
301+
metadata: {
302+
context_length: 48000,
303+
max_tokens: 4096,
304+
pricing: {},
305+
tags: ["chat", "reasoning_effort"],
306+
},
307+
}),
308+
];
309+
const mockFetch = vi.fn().mockResolvedValue(jsonResponse({ data: rows }));
310+
DEEPINFRA_MODEL_CATALOG.push(DEEPINFRA_MODEL_CATALOG[0]!);
311+
312+
try {
313+
await withFetchPathTest(mockFetch, { DEEPINFRA_API_KEY: "sk-test" }, async () => {
314+
const models = await discoverDeepInfraModels();
315+
316+
expect(models.slice(0, rows.length)).toMatchObject([
317+
{
318+
id: "deepseek-ai/DeepSeek-V4-Pro",
319+
reasoning: true,
320+
input: ["text"],
321+
contextWindow: 96000,
322+
maxTokens: 4096,
323+
cost: { input: 4, output: 8, cacheRead: 0.4, cacheWrite: 0 },
324+
compat: {
325+
codeMode: "capable",
326+
supportsUsageInStreaming: true,
327+
thinkingFormat: "deepseek",
328+
},
329+
},
330+
{
331+
id: "stepfun-ai/Step-3.7-Flash",
332+
reasoning: true,
333+
input: ["text", "image"],
334+
contextWindow: 192000,
335+
maxTokens: 16384,
336+
cost: { input: 0.2, output: 1.15, cacheRead: 0, cacheWrite: 0 },
337+
},
338+
{ id: "deepseek-ai/DeepSeek-V3.2", reasoning: false },
339+
{ id: "unlisted/no-reasoning", reasoning: false },
340+
{ id: "unlisted/with-reasoning", reasoning: true },
341+
]);
342+
expect(new Set(models.map((model) => model.id)).size).toBe(models.length);
343+
});
344+
} finally {
345+
DEEPINFRA_MODEL_CATALOG.pop();
346+
}
347+
});
348+
266349
it("skips entries with no metadata or no surface tag, and deduplicates ids", async () => {
267350
const mockFetch = vi.fn().mockResolvedValue(
268351
jsonResponse({

‎extensions/deepinfra/provider-models.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,15 @@ export function buildDeepInfraModelDefinition(model: ModelDefinitionConfig): Mod
359359
}
360360

361361
function chatSurfaceModelToModelDefinition(model: DeepInfraSurfaceModel): ModelDefinitionConfig {
362+
const manifestModel = DEEPINFRA_MODEL_CATALOG.find((entry) => entry.id === model.id);
362363
const input: Array<"text" | "image"> = model.tags.includes("vlm") ? ["text", "image"] : ["text"];
363364
const reasoning = model.tags.includes("reasoning") || model.tags.includes("reasoning_effort");
364365
return buildDeepInfraModelDefinition({
365366
id: model.id,
366367
name: model.name,
367-
reasoning,
368+
reasoning: manifestModel?.reasoning ?? reasoning,
368369
input,
370+
...(manifestModel?.compat ? { compat: manifestModel.compat } : {}),
369371
contextWindow: model.contextWindow ?? DEEPINFRA_DEFAULT_CONTEXT_WINDOW,
370372
maxTokens: model.maxTokens ?? DEEPINFRA_DEFAULT_MAX_TOKENS,
371373
cost: {
@@ -480,14 +482,10 @@ export async function discoverDeepInfraModels(options?: {
480482
}
481483
const liveModels = chatModels.map(chatSurfaceModelToModelDefinition);
482484
const seen = new Set(liveModels.map((model) => model.id));
483-
const manifestModels = DEEPINFRA_MODEL_CATALOG.map(buildDeepInfraModelDefinition).filter(
484-
(model) => {
485-
if (seen.has(model.id)) {
486-
return false;
487-
}
488-
seen.add(model.id);
489-
return true;
490-
},
491-
);
485+
const manifestModels = DEEPINFRA_MODEL_CATALOG.filter((model) => {
486+
const unseen = !seen.has(model.id);
487+
seen.add(model.id);
488+
return unseen;
489+
}).map(buildDeepInfraModelDefinition);
492490
return [...liveModels, ...manifestModels];
493491
}

0 commit comments

Comments
 (0)