fix: 修复 DeepSeek V4 Pro 推理模型 content 为空的问题#218
Conversation
根因: DeepSeek V4 Pro 等推理模型会将全部输出放在 reasoning_content 字段, 而 content 字段为空字符串。现有代码只读取 content,导致返回空结果。 修复内容: - LLMResponse 新增 reasoning_content 和 reasoning_tokens 字段 - 非流式路径:content 为空时 fallback 到 reasoning_content - 流式 done 事件:同上 fallback 逻辑 - 流式异常结束(无 finish_reason):同上 fallback 逻辑 - stream_llm_call 中记录 reasoning 统计日志
|
@Windelly is attempting to deploy a commit to the tsinghuaiiilove-2257's projects Team on Vercel. A member of the Team first needs to authorize it. |
Review Summary by Qodo(Agentic_describe updated until commit 3c0f8c0)Fix DeepSeek V4 Pro reasoning model empty content issue
WalkthroughsDescription• Add reasoning_content and reasoning_tokens fields to LLMResponse for reasoning models • Implement fallback logic to use reasoning_content when content is empty • Apply fallback in both non-streaming and streaming paths • Add keepalive events and logging for reasoning model diagnostics • Reduce log verbosity in code analysis service Diagramflowchart LR
A["LLM Response"] --> B{"Has content?"}
B -->|Yes| C["Use content"]
B -->|No| D{"Has reasoning_content?"}
D -->|Yes| E["Fallback to reasoning_content"]
D -->|No| F["Return empty"]
C --> G["LLMResponse with reasoning fields"]
E --> G
F --> G
File Changes1. backend/app/services/llm/types.py
|
Code Review by Qodo
1.
|
1. Token estimation order: move reasoning fallback before token estimation so estimates are based on final content (after fallback) 2. Reduce log noise: change 3 reasoning-fallback logger.warning to logger.info
|
@CodiumAI-Agent review |
|
Closing and reopening to trigger Qodo re-review after addressing feedback. |
|
Persistent review updated to latest commit daf0fad |
…estimate consistency
|
Round 2 fixes pushed. Reopening for Qodo re-review. |
|
Persistent review updated to latest commit da283e1 |
|
Round 3 fixes pushed. Reopening for Qodo. |
|
Persistent review updated to latest commit 3c0f8c0 |
根因分析
DeepSeek V4 Pro 等推理模型会将推理过程放在
reasoning_content字段,而content字段可能为空字符串。现有 LLM 适配器只读取content,导致返回空结果,Agent 无法获取任何输出。修复内容
1. LLMResponse 新增字段(types.py)
reasoning_content: Optional[str]- 存储推理内容reasoning_tokens: int- 推理 token 估算值2. 非流式路径 fallback(litellm_adapter.py)
reasoning_content(兼容__dict__兜底)content为空且reasoning_content非空时,fallback 到reasoning_content3. 流式路径 fallback(litellm_adapter.py)
reasoning_content(从 delta 中提取)reasoning_content和reasoning_tokens4. Agent base 统计日志(base.py)
stream_llm_call的 done 事件处理中,记录 reasoning 统计日志兼容性
reasoning_content默认为空,fallback 不触发LLMResponse新增字段有默认值,不破坏现有调用方