Skip to content

Commit 738b306

Browse files
authored
tweak: make interleaved reasoning_content default to true for openai compat deepseek setups (#24630)
1 parent 26cc537 commit 738b306

2 files changed

Lines changed: 76 additions & 8 deletions

File tree

packages/opencode/src/provider/provider.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,13 @@ const layer: Layer.Layer<
11351135

11361136
for (const [modelID, model] of Object.entries(provider.models ?? {})) {
11371137
const existingModel = parsed.models[model.id ?? modelID]
1138+
const apiID = model.id ?? existingModel?.api.id ?? modelID
1139+
const apiNpm =
1140+
model.provider?.npm ??
1141+
provider.npm ??
1142+
existingModel?.api.npm ??
1143+
modelsDev[providerID]?.npm ??
1144+
"@ai-sdk/openai-compatible"
11381145
const name = iife(() => {
11391146
if (model.name) return model.name
11401147
if (model.id && model.id !== modelID) return modelID
@@ -1143,13 +1150,8 @@ const layer: Layer.Layer<
11431150
const parsedModel: Model = {
11441151
id: ModelID.make(modelID),
11451152
api: {
1146-
id: model.id ?? existingModel?.api.id ?? modelID,
1147-
npm:
1148-
model.provider?.npm ??
1149-
provider.npm ??
1150-
existingModel?.api.npm ??
1151-
modelsDev[providerID]?.npm ??
1152-
"@ai-sdk/openai-compatible",
1153+
id: apiID,
1154+
npm: apiNpm,
11531155
url: model.provider?.api ?? provider?.api ?? existingModel?.api.url ?? modelsDev[providerID]?.api ?? "",
11541156
},
11551157
status: model.status ?? existingModel?.status ?? "active",
@@ -1177,7 +1179,12 @@ const layer: Layer.Layer<
11771179
model.modalities?.output?.includes("video") ?? existingModel?.capabilities.output.video ?? false,
11781180
pdf: model.modalities?.output?.includes("pdf") ?? existingModel?.capabilities.output.pdf ?? false,
11791181
},
1180-
interleaved: model.interleaved ?? existingModel?.capabilities.interleaved ?? false,
1182+
interleaved:
1183+
model.interleaved ??
1184+
existingModel?.capabilities.interleaved ??
1185+
(!existingModel && apiNpm === "@ai-sdk/openai-compatible" && apiID.includes("deepseek")
1186+
? { field: "reasoning_content" }
1187+
: false),
11811188
},
11821189
cost: {
11831190
input: model?.cost?.input ?? existingModel?.cost?.input ?? 0,

packages/opencode/test/provider/provider.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,67 @@ test("custom provider with npm package", async () => {
312312
})
313313
})
314314

315+
test("custom DeepSeek openai-compatible model defaults interleaved reasoning field", async () => {
316+
await using tmp = await tmpdir({
317+
init: async (dir) => {
318+
await Bun.write(
319+
path.join(dir, "opencode.json"),
320+
JSON.stringify({
321+
$schema: "https://opencode.ai/config.json",
322+
provider: {
323+
"custom-provider": {
324+
name: "Custom Provider",
325+
npm: "@ai-sdk/openai-compatible",
326+
api: "https://api.custom.com/v1",
327+
models: {
328+
"deepseek-r1": {
329+
name: "DeepSeek R1",
330+
},
331+
"deepseek-details": {
332+
name: "DeepSeek Details",
333+
interleaved: { field: "reasoning_details" },
334+
},
335+
"custom-model": {
336+
name: "Custom Model",
337+
},
338+
},
339+
options: {
340+
apiKey: "custom-key",
341+
},
342+
},
343+
"custom-anthropic-provider": {
344+
name: "Custom Anthropic Provider",
345+
npm: "@ai-sdk/anthropic",
346+
api: "https://api.custom.com/v1",
347+
models: {
348+
"deepseek-r1": {
349+
name: "DeepSeek R1",
350+
},
351+
},
352+
options: {
353+
apiKey: "custom-key",
354+
},
355+
},
356+
},
357+
}),
358+
)
359+
},
360+
})
361+
await Instance.provide({
362+
directory: tmp.path,
363+
fn: async () => {
364+
const providers = await list()
365+
const provider = providers[ProviderID.make("custom-provider")]
366+
expect(provider.models["deepseek-r1"].capabilities.interleaved).toEqual({ field: "reasoning_content" })
367+
expect(provider.models["deepseek-details"].capabilities.interleaved).toEqual({ field: "reasoning_details" })
368+
expect(provider.models["custom-model"].capabilities.interleaved).toBe(false)
369+
expect(
370+
providers[ProviderID.make("custom-anthropic-provider")].models["deepseek-r1"].capabilities.interleaved,
371+
).toBe(false)
372+
},
373+
})
374+
})
375+
315376
test("env variable takes precedence, config merges options", async () => {
316377
await using tmp = await tmpdir({
317378
init: async (dir) => {

0 commit comments

Comments
 (0)