fix deepseek v4 reasoning content problem in thinking mode#1
Closed
wya-tt wants to merge 1 commit intopanyw5:devfrom
Closed
fix deepseek v4 reasoning content problem in thinking mode#1wya-tt wants to merge 1 commit intopanyw5:devfrom
wya-tt wants to merge 1 commit intopanyw5:devfrom
Conversation
panyw5
added a commit
that referenced
this pull request
May 1, 2026
Cherry-pick the targeted DeepSeek interleaved-default tweak from upstream opencode (sst#24630, commit 738b306) and apply a properly scoped version of the empty-content preserving fix from #1. provider.ts (custom-provider parser only): - Default `interleaved` to { field: "reasoning_content" } only for brand-new openai-compatible providers whose api id contains "deepseek". Existing user/source config still wins via the ?? chain. fromModelsDevModel is intentionally left alone — models.dev already carries the explicit interleaved config for DeepSeek there. transform.ts (the existing interleaved branch): - Switch the providerOptions namespace from hard-coded "openaiCompatible" to sdkKey(model.api.npm) ?? "openaiCompatible" so providers wired through other AI SDKs land in the right slot. - Always emit the field (even when reasoningText is empty) so DeepSeek's follow-up tool-call requests stop 400-ing, and preserve any existing reasoning_content across re-transforms instead of overwriting with "". Deliberately does NOT add a fallback `if (model.capabilities.reasoning)` branch — that would inject reasoning_content into providerOptions for OpenAI o1/o3, Claude reasoning, Gemini thinking etc., which is not a valid key for those SDKs. tests: - Share a deepseekModel fixture across the DeepSeek tests. - Add empty-reasoning preservation regression. - Add re-transform existing-reasoning preservation regression. - Add reverse guard: OpenAI o1 (reasoning=true, interleaved=false) must NOT pick up reasoning_content in providerOptions. Supersedes #1 (that PR's broader scope would affect non-DeepSeek reasoning providers).
panyw5
reviewed
May 1, 2026
Owner
There was a problem hiding this comment.
谢谢提交。Bug 抓得对,patch 大方向也对,但作用域太宽。已在 dev (commit f5d2963) 落了一个收窄版。
采用了原 PR 的
transform.ts把硬编码的"openaiCompatible"换成sdkKey(model.api.npm) ?? "openaiCompatible"transform.ts总是写[field](即使为空字符串)+ 跨 transform 用||链保留已有reasoning_content——核心 bug fix- 测试 fixture 重构(共享
deepseekModel)+ 空 reasoning / 重复 transform 两个回归测试
没有采用的
provider.ts把interleaved兜底到所有model.reasoning === true的模型——会把 DeepSeek 专属字段套到 OpenAI o1/o3、Claude reasoning、Gemini thinking 上,污染它们的 providerOptionstransform.ts新增的if (model.capabilities.reasoning) { … }分支——同上,且会硬编码reasoning_content字段名,无视interleaved.field配置
改用 upstream 的设计
provider.ts 的 interleaved 默认值改为 anomalyco#24630(commit 738b3065d)的写法,三重门控:
interleaved:
model.interleaved ??
existingModel?.capabilities.interleaved ??
(!existingModel && apiNpm === "@ai-sdk/openai-compatible" && apiID.toLowerCase().includes("deepseek")
? { field: "reasoning_content" }
: false),只对全新 openai-compatible + DeepSeek 命名的模型默认开启,user/source config 仍然优先。fromModelsDevModel 那处不动——models.dev 已经显式给 DeepSeek 配了 interleaved。
额外加的
OpenAI o1-mini(reasoning=true, interleaved=false)transform 后不应有 providerOptions.openai.reasoning_content 的反向 guard,防止之后再有人想往这个方向扩。
Owner
|
Close pull request. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
What does this PR do?
This fixes DeepSeek reasoning message handling when assistant messages include tool calls. The changes is made by Cursor with GPT 5.5, based on the official update of OpenCode.
DeepSeek-compatible models can require
reasoning_contentto be sent back in provider options on later requests, including when the reasoning content is empty. Previously the transform could drop that field, which breaks follow-up tool-call flows.The change preserves existing
reasoning_content, keeps empty reasoning content instead of omitting it, and defaults reasoning-capable models to usereasoning_contentwhen no explicit interleaved field is configured.How did you verify your code works?
Added regression tests for DeepSeek provider transforms covering:
reasoning_contentChecklist