Skip to content

Commit 3216ce1

Browse files
committed
fix: NVIDIA NIM model compatibility issues
Thanks to @akarshjadhav21 for this :D - 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 829420b commit 3216ce1

3 files changed

Lines changed: 90 additions & 5 deletions

File tree

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

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

18811881
const info = provider.models[modelID]
18821882
if (!info) {
1883+
// For NVIDIA NIM models, the model ID itself contains slashes (e.g., "nvidia/nemotron-3-ultra-550b-a55b").
1884+
// Try prepending the provider ID to the model ID to handle the full model path.
1885+
if (providerID === "nvidia") {
1886+
const fullModelID = ModelV2.ID.make(`${providerID}/${modelID}`)
1887+
const fullInfo = provider.models[fullModelID]
1888+
if (fullInfo) return fullInfo
1889+
}
1890+
18831891
const current = modelSuggestions(provider, modelID, runtimeFlags.enableExperimentalModels)
18841892
const suggestions = current.length
18851893
? current
@@ -2065,4 +2073,28 @@ export const node = LayerNode.make({
20652073
deps: [FSUtil.node, Config.node, Auth.node, Env.node, Plugin.node, ModelsDev.node, RuntimeFlags.node],
20662074
})
20672075

2076+
// Try to resolve a model reference that may contain multiple slashes.
2077+
// For NVIDIA NIM models, the model ID itself contains slashes (e.g., "nvidia/nemotron-3-ultra-550b-a55b"),
2078+
// so the full reference is "nvidia/nvidia/nemotron-3-ultra-550b-a55b".
2079+
export function parseModelRef(model: string, providers: Record<string, any>) {
2080+
// First try the standard split (first slash = provider)
2081+
const parsed = parseModel(model)
2082+
if (providers[parsed.providerID]?.models[parsed.modelID]) {
2083+
return parsed
2084+
}
2085+
2086+
// Try splitting on the second slash (for NVIDIA-style IDs like "nvidia/nvidia/model-name")
2087+
const parts = model.split("/")
2088+
if (parts.length >= 3) {
2089+
const providerID = ProviderV2.ID.make(parts[0])
2090+
const modelID = ModelV2.ID.make(parts.slice(1).join("/"))
2091+
if (providers[providerID]?.models[modelID]) {
2092+
return { providerID, modelID }
2093+
}
2094+
}
2095+
2096+
return parsed
2097+
}
2098+
2099+
20682100
export * as Provider from "./provider"

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

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

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

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ describe("ProviderTransform.variants", () => {
38783878
})
38793879
})
38803880

3881-
test.each(["nvidia", "lilac"])("%s minimax m3 returns chat template thinking toggles", (providerID) => {
3881+
test.each(["nvidia", "lilac"])("%s minimax m3 returns thinking type toggles (NIM compatible)", (providerID) => {
38823882
const model = createMockModel({
38833883
id: `${providerID}/minimaxai/minimax-m3`,
38843884
providerID,
@@ -3888,9 +3888,10 @@ describe("ProviderTransform.variants", () => {
38883888
npm: "@ai-sdk/openai-compatible",
38893889
},
38903890
})
3891+
// NIM only accepts thinking.type "enabled" or "disabled" (not "adaptive")
38913892
expect(ProviderTransform.variants(model)).toEqual({
3892-
none: { chat_template_kwargs: { thinking_mode: "disabled" } },
3893-
thinking: { chat_template_kwargs: { thinking_mode: "enabled" } },
3893+
none: { thinking: { type: "disabled" } },
3894+
thinking: { thinking: { type: "enabled" } },
38943895
})
38953896
})
38963897

0 commit comments

Comments
 (0)