fix: DeepSeek V4 proxy model recognition — substring match instead of exact set match for reasoning_content injection#9015
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The substring-based
_deepseek_v4_markersmatch is broader than the previous exact set and could accidentally classify unrelated models that happen to containdeepseek-v4; consider constraining this further (e.g., prefix match or a more structured pattern) to avoid false positives. - The DeepSeek V4 detection logic is starting to accumulate special cases (markers, host checks, explicit exclusions); it may be clearer and easier to maintain if extracted into a dedicated helper with well-documented rules, reused wherever DeepSeek reasoning behavior is needed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The substring-based `_deepseek_v4_markers` match is broader than the previous exact set and could accidentally classify unrelated models that happen to contain `deepseek-v4`; consider constraining this further (e.g., prefix match or a more structured pattern) to avoid false positives.
- The DeepSeek V4 detection logic is starting to accumulate special cases (markers, host checks, explicit exclusions); it may be clearer and easier to maintain if extracted into a dedicated helper with well-documented rules, reused wherever DeepSeek reasoning behavior is needed.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request updates the DeepSeek v4 reasoning model detection logic in openai_source.py by expanding the model markers and excluding specific chat and reasoner models. The review feedback suggests simplifying this logic by removing redundant substring checks and consolidating the conditions into a single assignment expression.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| _deepseek_v4_markers = ("deepseek-v4-pro", "deepseek-v4-flash", "deepseek-v4") | ||
| is_deepseek_v4_reasoning = ( | ||
| model in deepseek_reasoning_models | ||
| any(marker in model for marker in _deepseek_v4_markers) | ||
| or "api.deepseek.com" in self.client.base_url.host | ||
| ) | ||
| if is_deepseek_v4_reasoning and ( | ||
| "deepseek-chat" in model or "deepseek-reasoner" in model | ||
| ): | ||
| is_deepseek_v4_reasoning = False |
There was a problem hiding this comment.
Since "deepseek-v4" is a substring of both "deepseek-v4-pro" and "deepseek-v4-flash", checking for those specific markers is redundant. We can simplify the entire logic into a single, clean assignment expression, which also avoids re-assigning is_deepseek_v4_reasoning.
is_deepseek_v4_reasoning = (
"deepseek-v4" in model
or "api.deepseek.com" in self.client.base_url.host
) and not (
"deepseek-chat" in model or "deepseek-reasoner" in model
)
Summary / 概述
Fix link: Closes #9008
_finally_convert_payload()中对 DeepSeek V4 的模型识别使用精确集合匹配,导致通过代理/中转使用 DeepSeek V4 的用户(模型 ID 带前缀如opencode/deepseek-v4-pro)无法被识别,reasoning_content未被注入,引发 HTTP 400。本 PR 将精确匹配改为子串匹配,与 MiMo 模型在 #8327 中采用的模式一致。
Root Cause / 根因
代理模型 ID 如
opencode/deepseek-v4-pro既不在精确集合中,host 也不是api.deepseek.com,两条判断路径均失败 →is_deepseek_v4_reasoning=False→ assistant 消息缺少reasoning_content→ API 400。Changes / 改动
文件:
astrbot/core/provider/sources/openai_source.py—_finally_convert_payload()(L936-940)改动要点:
model in set→any(marker in model):覆盖所有代理前缀"deepseek-v4"兜底标记:兼容未来子型号deepseek-chat/deepseek-reasoner(v3 模型无需 reasoning_content)api.deepseek.comhost 判断以向后兼容Verification / 验证
deepseek-v4-pro(直连)deepseek-v4-flash(直连)opencode/deepseek-v4-proopencode/deepseek-v4-flash星见雅/deepseek-v4-pro星见雅/deepseek-v4-flashdeepseek-chat(v3)deepseek-reasoner(v3)qwen3.6-plus(非 DeepSeek)真实日志验证(AstrBot v4.25.5,
opencode/deepseek-v4-flash):Relation to #8483 / 与 #8483 的关系
本 PR 与 #8483(
_sanitize_assistant_messages中保留带reasoning_content的消息)互补:reasoning_content被正确注入_sanitize误删除两者合起来形成 DeepSeek V4 代理场景的完整覆盖。
Checklist
Summary by Sourcery
Relax DeepSeek V4 model detection to support proxy-prefixed model IDs while keeping non-V4 DeepSeek models excluded from reasoning payload injection.
Bug Fixes:
Enhancements: