Skip to content

feat: return reasoning_content with tool_calls for DeepSeek models#2543

Merged
farion1231 merged 3 commits into
farion1231:mainfrom
bling-yshs:feat/deepseek-toolcalls
May 7, 2026
Merged

feat: return reasoning_content with tool_calls for DeepSeek models#2543
farion1231 merged 3 commits into
farion1231:mainfrom
bling-yshs:feat/deepseek-toolcalls

Conversation

@bling-yshs

@bling-yshs bling-yshs commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary / 概述

Add DeepSeek to the OpenAI Chat reasoning_content compatibility path so DeepSeek tool call requests preserve reasoning_content alongside tool_calls, matching the existing Moonshot/Kimi behavior.

为 DeepSeek 接入 OpenAI Chat 的 reasoning_content 兼容逻辑,使 DeepSeek 在工具调用场景下与现有 Moonshot/Kimi 行为一致,在 tool_calls 同级回传 reasoning_content

Related Issue / 关联 Issue

Fixes #2282 #2277 #2531

Screenshots / 截图

Before / 修改前 After / 修改后
image PixPin_2026-05-03_10-28-37

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件

cargo clippy 因为其他文件而不通过

Copy link
Copy Markdown
Owner

@codex review
@claude review

@claude

claude Bot commented May 3, 2026

Copy link
Copy Markdown

Claude finished @farion1231's task in 1m 9s —— View job


Review: PR #2543

  • Read CLAUDE.md and PR diff
  • Review claude.rs changes
  • Review transform.rs changes
  • Post review

LGTM — no blocking issues.

Small, well-scoped change that extends the existing Moonshot/Kimi reasoning_content compatibility path to DeepSeek by:

  1. Renaming is_moonshot_or_kimi_identifieris_reasoning_content_compatible_identifier and adding "deepseek" to the substring match (src-tauri/src/proxy/providers/claude.rs:85-88).
  2. Updating the two doc comments in transform.rs to mention DeepSeek.
  3. Adding a parallel unit test for the DeepSeek path (claude.rs:1678-1710) that mirrors the existing Kimi test.

The substring-match approach (value.contains("deepseek") against model id and ANTHROPIC_BASE_URL/base_url/baseURL/apiEndpoint) is consistent with how moonshot/kimi were already detected, and DeepSeek genuinely supports the non-standard reasoning_content field in tool-call replays, so the gating is correct. No new risks introduced beyond what the existing predicate already had.

Note on the unchecked clippy box in the PR description: cargo clippy failures in unrelated files are not introduced by this PR, but worth confirming locally that the renamed function and new test don't add any new lints before merge.
• Branch: feat/deepseek-toolcalls

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常感谢您的贡献,请查看一下有以下问题吗:

PR #2543 方向正确,但目前只解决了请求侧识别 DeepSeek 并尝试回传 reasoning_content。

真正修复 #2282 还需要补响应侧转换,否则真实的 DeepSeek reasoning_content 会在返回给 Claude Code 时丢失。

需要修改 streaming.rs::Delta:为 reasoning 增加 #[serde(alias = "reasoning_content")],兼容 DeepSeek 流式返回字段。

需要修改 openai_to_anthropic:把非流式响应里的 message.reasoning_content 映射为 Anthropic thinking block。

当前代码在拿不到真实 thinking 时会回传占位 "tool call",这不满足 DeepSeek tool call 场景“必须完整传回 reasoning_content”的要求,仍可能导致 400,或造成 thinking 丢失、答案质量下降、调试困难

@bling-yshs

Copy link
Copy Markdown
Contributor Author

非常感谢您的贡献,请查看一下有以下问题吗:

PR #2543 方向正确,但目前只解决了请求侧识别 DeepSeek 并尝试回传 reasoning_content。

真正修复 #2282 还需要补响应侧转换,否则真实的 DeepSeek reasoning_content 会在返回给 Claude Code 时丢失。

需要修改 streaming.rs::Delta:为 reasoning 增加 #[serde(alias = "reasoning_content")],兼容 DeepSeek 流式返回字段。

需要修改 openai_to_anthropic:把非流式响应里的 message.reasoning_content 映射为 Anthropic thinking block。

当前代码在拿不到真实 thinking 时会回传占位 "tool call",这不满足 DeepSeek tool call 场景“必须完整传回 reasoning_content”的要求,仍可能导致 400,或造成 thinking 丢失、答案质量下降、调试困难

确实有问题,我修改一下

@bling-yshs

bling-yshs commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@farion1231 修改好了

PixPin_2026-05-07_22-07-18

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢您的贡献!

@farion1231
farion1231 merged commit f5fbcd0 into farion1231:main May 7, 2026
3 checks passed
ManLOK-Chu pushed a commit to ManLOK-Chu/cc-switch that referenced this pull request May 11, 2026
…arion1231#2543)

* feat: return reasoning_content with tool_calls for DeepSeek models

* fix: correct reasoning_content handling for DeepSeek tool_calls

* test: cover DeepSeek reasoning content round trip

---------

Co-authored-by: Jason <[email protected]>
dfbb pushed a commit to dfbb/cc-switch that referenced this pull request May 20, 2026
…arion1231#2543)

* feat: return reasoning_content with tool_calls for DeepSeek models

* fix: correct reasoning_content handling for DeepSeek tool_calls

* test: cover DeepSeek reasoning content round trip

---------

Co-authored-by: Jason <[email protected]>
WangXingFan pushed a commit to WangXingFan/cc-switch that referenced this pull request May 23, 2026
…arion1231#2543)

* feat: return reasoning_content with tool_calls for DeepSeek models

* fix: correct reasoning_content handling for DeepSeek tool_calls

* test: cover DeepSeek reasoning content round trip

---------

Co-authored-by: Jason <[email protected]>
delta-lo pushed a commit to delta-lo/cc-switch-mod that referenced this pull request May 31, 2026
…arion1231#2543)

* feat: return reasoning_content with tool_calls for DeepSeek models

* fix: correct reasoning_content handling for DeepSeek tool_calls

* test: cover DeepSeek reasoning content round trip

---------

Co-authored-by: Jason <[email protected]>
jeffusion added a commit to jeffusion/bungee that referenced this pull request Jul 6, 2026
Preserve reasoning_content alongside tool_calls for DeepSeek/Moonshot/Kimi
models. When an assistant message contains both thinking content and
tool_calls, extract thinking into the reasoning_content field at the
message level — required by these providers to avoid upstream errors.

Reference: farion1231/cc-switch#2543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants