fix(gemini): preserve thinking across relay formats - #2
Open
karlorz wants to merge 3 commits into
Open
Conversation
问题: 在非 passThrough 模式下,客户端发送的 reasoning_content: "" 经过 Go struct 反序列化再序列化后,因 string + omitempty 无法区分空串和 字段缺失,导致空的思考内容被静默丢弃。 根因: dto.Message.ReasoningContent 和 Message.Reasoning 使用 string(非指针) 加 omitempty,违反 AGENTS.md Rule 6(可选标量字段必须用指针类型)。 修复: 1. Message.ReasoningContent/Reasoning 类型从 string 改为 *string - nil = 字段缺失 → JSON 省略 - &"" = 显式空串 → JSON 保留 reasoning_content: "" 2. 新增 Message.GetReasoningContent() 辅助方法 3. 更新所有读写处:relay-openai, relay-claude, relay-gemini, ollama 4. 新增测试覆盖空串保留、字段省略、getter 回退逻辑 (cherry picked from commit 8ca1033)
(cherry picked from commit 465c5ed)
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.
📝 变更描述 / Description
修复 Gemini 思考内容在跨 relay 格式转换时丢失的问题。具体:
8ca103342d, ReasoningContent/Reasoning 改为 *string,修复空思考内容被静默丢弃) 和 fix:gemini to claude tool_use err QuantumNous/new-api#5041 (465c5eda, gemini→claude tool_use 修复)97e79ae85: GeminiThinkingConfig 字段指针化(显式 includeThoughts:false 不再被 omitempty 丢弃); 新增 resolveClaudeThinkingConfig 将 Claude thinking.type (disabled/enabled/adaptive) 与 output_config.effort 翻译为 Gemini thinking 配置; reasoning_effort 透传为原生 ThinkingLevel; Gemini thought parts 与 text/tool calls 分离; Claude 转换输出合法 thinking blocks(流式与非流式)生效原理: 请求侧显式 thinking 配置优先于通用 effort 映射; 响应侧 thought 部件独立收集为 reasoning_content/thinking blocks, 不与正文或工具调用混合。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
gemini-xxxx-thinking或gemini-xxxx-thinking-xxxx时,includeThoughts被意外设置为trueQuantumNous/new-api#1390, fix: preserve Gemini thought and content in same chunk QuantumNous/new-api#5094, fix(relayconvert): preserve assistant reasoning across request protocol conversions QuantumNous/new-api#6593 (上游均未合并; 本 PR 为 fork 发布线 v0.13 的独立修复)✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work