Skip to content

Commit 8821173

Browse files
fix: NVIDIA NIM model compatibility issues
- DeepSeek v4: Add chat_template_kwargs to enable thinking (fixes silent stall) See: anomalyco#24264 - Nemotron 3 Ultra: Add chat_template_kwargs to enable thinking (fixes hang) See: anomalyco#34026 - MiniMax M3: Use thinking.type instead of chat_template_kwargs for NIM compatibility (NIM only accepts thinking.type 'enabled' or 'disabled', not 'adaptive') - Model ID slash fix: Try prepending provider ID for NVIDIA NIM models with slash-containing IDs (e.g., nvidia/nvidia/nemotron-3-ultra-550b-a55b)
1 parent c5ef753 commit 8821173

3 files changed

Lines changed: 89 additions & 5 deletions

File tree

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,14 @@ const layer = Layer.effect(
18791879

18801880
const info = provider.models[modelID]
18811881
if (!info) {
1882+
// For NVIDIA NIM models, the model ID itself contains slashes (e.g., "nvidia/nemotron-3-ultra-550b-a55b").
1883+
// Try prepending the provider ID to the model ID to handle the full model path.
1884+
if (providerID === "nvidia") {
1885+
const fullModelID = ModelV2.ID.make(`${providerID}/${modelID}`)
1886+
const fullInfo = provider.models[fullModelID]
1887+
if (fullInfo) return fullInfo
1888+
}
1889+
18821890
const current = modelSuggestions(provider, modelID, runtimeFlags.enableExperimentalModels)
18831891
const suggestions = current.length
18841892
? current
@@ -2058,6 +2066,29 @@ export function parseModel(model: string) {
20582066
}
20592067
}
20602068

2069+
// Try to resolve a model reference that may contain multiple slashes.
2070+
// For NVIDIA NIM models, the model ID itself contains slashes (e.g., "nvidia/nemotron-3-ultra-550b-a55b"),
2071+
// so the full reference is "nvidia/nvidia/nemotron-3-ultra-550b-a55b".
2072+
export function parseModelRef(model: string, providers: Record<string, any>) {
2073+
// First try the standard split (first slash = provider)
2074+
const parsed = parseModel(model)
2075+
if (providers[parsed.providerID]?.models[parsed.modelID]) {
2076+
return parsed
2077+
}
2078+
2079+
// Try splitting on the second slash (for NVIDIA-style IDs like "nvidia/nvidia/model-name")
2080+
const parts = model.split("/")
2081+
if (parts.length >= 3) {
2082+
const providerID = ProviderV2.ID.make(parts[0])
2083+
const modelID = ModelV2.ID.make(parts.slice(1).join("/"))
2084+
if (providers[providerID]?.models[modelID]) {
2085+
return { providerID, modelID }
2086+
}
2087+
}
2088+
2089+
return parsed
2090+
}
2091+
20612092
export const node = LayerNode.make({
20622093
service: Service,
20632094
layer: layer,

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,10 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
736736
["@ai-sdk/anthropic", "@ai-sdk/openai-compatible"].includes(model.api.npm)
737737
) {
738738
if (["nvidia", "lilac"].includes(model.providerID)) {
739+
// NIM only accepts thinking.type "enabled" or "disabled" (not "adaptive")
739740
return {
740-
none: { chat_template_kwargs: { thinking_mode: "disabled" } },
741-
thinking: { chat_template_kwargs: { thinking_mode: "enabled" } },
741+
none: { thinking: { type: "disabled" } },
742+
thinking: { thinking: { type: "enabled" } },
742743
}
743744
}
744745
return {
@@ -1232,6 +1233,28 @@ export function options(input: {
12321233
result["thinking"] = { type: "adaptive" }
12331234
}
12341235

1236+
// NVIDIA NIM DeepSeek v4 models require chat_template_kwargs to enable thinking.
1237+
// Without it, NIM silently stalls and never returns a response.
1238+
// See: https://github.com/anomalyco/opencode/issues/24264
1239+
if (
1240+
input.model.providerID === "nvidia" &&
1241+
input.model.api.npm === "@ai-sdk/openai-compatible" &&
1242+
modelId.includes("deepseek-v4")
1243+
) {
1244+
result["chat_template_kwargs"] = { enable_thinking: true, thinking: true }
1245+
}
1246+
1247+
// NVIDIA NIM Nemotron 3 Ultra and other Nemotron reasoning models may hang
1248+
// without explicit thinking enablement. Enable thinking by default.
1249+
// See: https://github.com/anomalyco/opencode/issues/34026
1250+
if (
1251+
input.model.providerID === "nvidia" &&
1252+
input.model.api.npm === "@ai-sdk/openai-compatible" &&
1253+
modelId.includes("nemotron-3-ultra")
1254+
) {
1255+
result["chat_template_kwargs"] = { enable_thinking: true }
1256+
}
1257+
12351258
// Moonshot's Anthropic-compatible API uses adaptive effort rather than token budgets.
12361259
// Request summaries so thinking content survives replay on subsequent turns.
12371260
if (
@@ -1346,6 +1369,35 @@ export function smallOptions(model: Provider.Model) {
13461369
return { veniceParameters: { disableThinking: true } }
13471370
}
13481371

1372+
// NVIDIA NIM DeepSeek v4 models require chat_template_kwargs even for small requests
1373+
// (title/summary generation). Without it, NIM silently stalls.
1374+
const modelId = model.api.id.toLowerCase()
1375+
if (
1376+
model.providerID === "nvidia" &&
1377+
model.api.npm === "@ai-sdk/openai-compatible" &&
1378+
modelId.includes("deepseek-v4")
1379+
) {
1380+
return mergeDeep(small, { chat_template_kwargs: { enable_thinking: true, thinking: true } })
1381+
}
1382+
1383+
// NVIDIA NIM Nemotron 3 Ultra also needs thinking enabled for small requests
1384+
if (
1385+
model.providerID === "nvidia" &&
1386+
model.api.npm === "@ai-sdk/openai-compatible" &&
1387+
modelId.includes("nemotron-3-ultra")
1388+
) {
1389+
return mergeDeep(small, { chat_template_kwargs: { enable_thinking: true } })
1390+
}
1391+
1392+
// NVIDIA NIM MiniMax M3 needs thinking enabled for small requests
1393+
if (
1394+
model.providerID === "nvidia" &&
1395+
model.api.npm === "@ai-sdk/openai-compatible" &&
1396+
modelId.includes("minimax-m3")
1397+
) {
1398+
return mergeDeep(small, { thinking: { type: "enabled" } })
1399+
}
1400+
13491401
return small
13501402
}
13511403

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,7 +3749,7 @@ describe("ProviderTransform.variants", () => {
37493749
})
37503750
})
37513751

3752-
test.each(["nvidia", "lilac"])("%s minimax m3 returns chat template thinking toggles", (providerID) => {
3752+
test.each(["nvidia", "lilac"])("%s minimax m3 returns thinking type toggles (NIM compatible)", (providerID) => {
37533753
const model = createMockModel({
37543754
id: `${providerID}/minimaxai/minimax-m3`,
37553755
providerID,
@@ -3759,9 +3759,10 @@ describe("ProviderTransform.variants", () => {
37593759
npm: "@ai-sdk/openai-compatible",
37603760
},
37613761
})
3762+
// NIM only accepts thinking.type "enabled" or "disabled" (not "adaptive")
37623763
expect(ProviderTransform.variants(model)).toEqual({
3763-
none: { chat_template_kwargs: { thinking_mode: "disabled" } },
3764-
thinking: { chat_template_kwargs: { thinking_mode: "enabled" } },
3764+
none: { thinking: { type: "disabled" } },
3765+
thinking: { thinking: { type: "enabled" } },
37653766
})
37663767
})
37673768

0 commit comments

Comments
 (0)