Guest User

Untitled

a guest
Aug 7th, 2026
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts
  2. index 9d98815cda..3ad35e5b2a 100644
  3. --- a/packages/opencode/src/provider/transform.ts
  4. +++ b/packages/opencode/src/provider/transform.ts
  5. @@ -1251,6 +1251,18 @@ export function options(input: {
  6. result["enable_thinking"] = true
  7. }
  8.  
  9. + // NVIDIA NIM's DeepSeek v4 reasoning models require `chat_template_kwargs` at the
  10. + // request body root on the openai-compatible transport to stream reasoning_content.
  11. + // Without it the request hangs indefinitely (see #24264). Keep thinking on even for
  12. + // the "none" effort variant — NIM hangs when enable_thinking is false.
  13. + if (
  14. + input.model.providerID === "nvidia" &&
  15. + input.model.api.npm === "@ai-sdk/openai-compatible" &&
  16. + input.model.api.id.toLowerCase().includes("deepseek-v4")
  17. + ) {
  18. + result["chat_template_kwargs"] = { thinking: true, enable_thinking: true }
  19. + }
  20. +
  21. if (input.providerOptions?.setCacheKey !== false) {
  22. if (input.model.api.npm === "@ai-sdk/deepinfra" || input.model.api.npm === "@ai-sdk/cerebras") {
  23. result["prompt_cache_key"] = input.sessionID
  24. @@ -1340,6 +1352,17 @@ export function smallOptions(model: Provider.Model) {
  25. return { veniceParameters: { disableThinking: true } }
  26. }
  27.  
  28. + // NVIDIA NIM's DeepSeek v4 hangs on requests that disable reasoning
  29. + // (enable_thinking:false), so the title/summary path must keep thinking enabled
  30. + // even though the first variant would otherwise turn it off (see #24264).
  31. + if (
  32. + model.providerID === "nvidia" &&
  33. + model.api.npm === "@ai-sdk/openai-compatible" &&
  34. + model.api.id.toLowerCase().includes("deepseek-v4")
  35. + ) {
  36. + return { chat_template_kwargs: { thinking: true, enable_thinking: true } }
  37. + }
  38. +
  39. return small
  40. }
  41.  
  42. @@ -1711,6 +1734,17 @@ function reasoningToggle(model: Provider.Model): NonNullable<Provider.Model["var
  43. }
  44.  
  45. function reasoningEffort(model: Provider.Model, effort: string) {
  46. + // NVIDIA NIM's DeepSeek v4 reads `chat_template_kwargs` (with both `thinking` and
  47. + // `enable_thinking`) and ignores the generic `reasoningEffort` field, so translate
  48. + // efforts into the kwarg shape it expects. NIM hangs when thinking is disabled, so
  49. + // even the "none" effort keeps enable_thinking on.
  50. + if (
  51. + model.providerID === "nvidia" &&
  52. + model.api.npm === "@ai-sdk/openai-compatible" &&
  53. + model.api.id.toLowerCase().includes("deepseek-v4")
  54. + ) {
  55. + return { chat_template_kwargs: { thinking: true, enable_thinking: true } }
  56. + }
  57. switch (model.api.npm) {
  58. case "@openrouter/ai-sdk-provider":
  59. return { reasoning: { effort } }
  60. diff --git a/packages/opencode/test/provider/transform.test.ts b/packages/opencode/test/provider/transform.test.ts
  61. index 9897c543fb..948124c740 100644
  62. --- a/packages/opencode/test/provider/transform.test.ts
  63. +++ b/packages/opencode/test/provider/transform.test.ts
  64. @@ -387,6 +387,63 @@ describe("ProviderTransform.options - minimax m3 thinking", () => {
  65. })
  66. })
  67.  
  68. +describe("ProviderTransform.options - nvidia deepseek-v4 chat_template_kwargs", () => {
  69. + const createModel = (apiID: string, reasoning = true) =>
  70. + ({
  71. + id: `nvidia/${apiID}`,
  72. + providerID: "nvidia",
  73. + api: { id: apiID, url: "https://integrate.api.nvidia.com/v1", npm: "@ai-sdk/openai-compatible" },
  74. + capabilities: { reasoning },
  75. + limit: { output: 64_000 },
  76. + }) as any
  77. +
  78. + test.each(["deepseek-ai/deepseek-v4-flash", "deepseek-ai/deepseek-v4-pro"])(
  79. + "emits default-on chat_template_kwargs for nvidia deepseek-v4 model %s",
  80. + (apiID) => {
  81. + expect(
  82. + ProviderTransform.options({
  83. + model: createModel(apiID),
  84. + sessionID: "test-session-123",
  85. + }).chat_template_kwargs,
  86. + ).toEqual({ thinking: true, enable_thinking: true })
  87. + },
  88. + )
  89. +
  90. + test("omits chat_template_kwargs for nvidia reasoning models that are not deepseek-v4", () => {
  91. + expect(
  92. + ProviderTransform.options({
  93. + model: createModel("google/gemma-4-31b-it"),
  94. + sessionID: "test-session-123",
  95. + }).chat_template_kwargs,
  96. + ).toBeUndefined()
  97. + expect(
  98. + ProviderTransform.options({
  99. + model: createModel("mistralai/mistral-medium-3.5-128b"),
  100. + sessionID: "test-session-123",
  101. + }).chat_template_kwargs,
  102. + ).toBeUndefined()
  103. + })
  104. +
  105. + test("omits chat_template_kwargs for non-reasoning nvidia models", () => {
  106. + expect(
  107. + ProviderTransform.options({
  108. + model: createModel("mistralai/mistral-medium-3-instruct", false),
  109. + sessionID: "test-session-123",
  110. + }).chat_template_kwargs,
  111. + ).toBeUndefined()
  112. + })
  113. +
  114. + test("omits chat_template_kwargs for non-nvidia openai-compatible deepseek-v4 models", () => {
  115. + const model = { ...createModel("deepseek-ai/deepseek-v4-pro"), providerID: "openrouter" }
  116. + expect(
  117. + ProviderTransform.options({
  118. + model,
  119. + sessionID: "test-session-123",
  120. + }).chat_template_kwargs,
  121. + ).toBeUndefined()
  122. + })
  123. +})
  124. +
  125. describe("ProviderTransform.options - google thinkingConfig gating", () => {
  126. const sessionID = "test-session-123"
  127.  
  128. @@ -3597,6 +3654,35 @@ describe("ProviderTransform.reasoningVariants", () => {
  129. )
  130. },
  131. )
  132. +
  133. + test("nvidia deepseek-v4 effort models emit chat_template_kwargs variants with thinking on", () => {
  134. + const t = {
  135. + id: "deepseek-ai/deepseek-v4-pro",
  136. + providerID: "nvidia",
  137. + api: { id: "deepseek-ai/deepseek-v4-pro", url: "", npm: "@ai-sdk/openai-compatible" },
  138. + capabilities: { reasoning: true },
  139. + limit: { output: 64_000 },
  140. + } as any
  141. + expect(ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["none", "high", "max"] }]), t)).toEqual({
  142. + none: { chat_template_kwargs: { thinking: true, enable_thinking: true } },
  143. + high: { chat_template_kwargs: { thinking: true, enable_thinking: true } },
  144. + max: { chat_template_kwargs: { thinking: true, enable_thinking: true } },
  145. + })
  146. + })
  147. +
  148. + test("non-deepseek-v4 nvidia reasoning models keep generic effort variants", () => {
  149. + const t = {
  150. + id: "mistralai/mistral-medium-3.5-128b",
  151. + providerID: "nvidia",
  152. + api: { id: "mistralai/mistral-medium-3.5-128b", url: "", npm: "@ai-sdk/openai-compatible" },
  153. + capabilities: { reasoning: true },
  154. + limit: { output: 64_000 },
  155. + } as any
  156. + expect(ProviderTransform.reasoningVariants(model([{ type: "effort", values: ["none", "high"] }]), t)).toEqual({
  157. + none: { reasoningEffort: "none" },
  158. + high: { reasoningEffort: "high" },
  159. + })
  160. + })
  161. })
  162.  
  163. describe("ProviderTransform.variants", () => {
  164.  
Advertisement
Add Comment
Please, Sign In to add comment