feat(provider): 添加 DeepSeek V4 思考模式开关和思考强度配置#7860
Open
piexian wants to merge 2 commits intoAstrBotDevs:masterfrom
Open
feat(provider): 添加 DeepSeek V4 思考模式开关和思考强度配置#7860piexian wants to merge 2 commits intoAstrBotDevs:masterfrom
piexian wants to merge 2 commits intoAstrBotDevs:masterfrom
Conversation
新增 deepseek_thinking_enabled 和 deepseek_reasoning_effort 配置项, 自动注入 thinking 到 extra_body 并设置 reasoning_effort。
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
_deepseek_reasoning_effort, you currently usepayloads.setdefault('reasoning_effort', ...), which lets a caller-providedreasoning_effortsilently override the provider config; consider explicitly deciding whether provider config or caller payload should have precedence and implement that (e.g., always overwrite or only allow a specific whitelist of values) to avoid surprising behavior. - Since
_config_flag_enabledis now the canonical way to interpret bool-like config values, you might want to reuse it for other similar flags in this provider (and potentially centralize its usage) to keep behavior consistent across different providers’ boolean options.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_deepseek_reasoning_effort`, you currently use `payloads.setdefault('reasoning_effort', ...)`, which lets a caller-provided `reasoning_effort` silently override the provider config; consider explicitly deciding whether provider config or caller payload should have precedence and implement that (e.g., always overwrite or only allow a specific whitelist of values) to avoid surprising behavior.
- Since `_config_flag_enabled` is now the canonical way to interpret bool-like config values, you might want to reuse it for other similar flags in this provider (and potentially centralize its usage) to keep behavior consistent across different providers’ boolean options.
## Individual Comments
### Comment 1
<location path="astrbot/core/provider/sources/openai_source.py" line_range="515-521" />
<code_context>
+ if normalized in {"high", "max"}:
+ return normalized
+ if value not in (None, ""):
+ logger.warning(
+ f"Invalid DeepSeek reasoning effort: {value}, falling back to high"
+ )
+ return "high"
+
</code_context>
<issue_to_address>
**suggestion (performance):** Repeated warnings for invalid DeepSeek reasoning effort might be noisy at runtime
Since `_deepseek_reasoning_effort` runs on every DeepSeek request, a bad setting will trigger this warning each time and can overwhelm logs in high-traffic environments. Consider validating once at config load, downgrading to debug or adding rate limiting, or caching the normalized value so the warning is only emitted once per invalid configuration.
```suggestion
def _deepseek_reasoning_effort(self) -> str:
# Cache the normalized value so we only validate and potentially log once
cached = getattr(self, "_deepseek_reasoning_effort_cached", None)
if cached is not None:
return cached
value = self.provider_config.get("deepseek_reasoning_effort", "high")
normalized_value = "high"
if isinstance(value, str):
normalized = value.strip().lower()
if normalized in {"high", "max"}:
normalized_value = normalized
elif value not in (None, ""):
logger.warning(
f"Invalid DeepSeek reasoning effort: {value}, falling back to high"
)
elif value not in (None, ""):
logger.warning(
f"Invalid DeepSeek reasoning effort: {value}, falling back to high"
)
self._deepseek_reasoning_effort_cached = normalized_value
return normalized_value
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for DeepSeek's thinking mode and reasoning effort, including configuration defaults, request override logic in the OpenAI source, and dashboard integration. Feedback identifies that enabling thinking mode by default may lead to 400 errors with the official DeepSeek API due to non-standard parameter formatting. Further improvements are suggested to ensure compatibility with older OpenAI SDK versions when handling the reasoning_effort parameter and to adhere to standard OpenAI values for reasoning effort levels.
- 将 reasoning_effort 从 setdefault 改为直接赋值,确保 provider 配置始终生效 - 缓存 _deepseek_reasoning_effort 结果,避免重复计算和重复警告 - 新增测试覆盖配置优先级和警告去重场景
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.
Modifications / 改动点
新增 deepseek_thinking_enabled 和 deepseek_reasoning_effort 配置项, 自动注入 thinking 到 extra_body 并设置 reasoning_effort。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add configurable DeepSeek thinking mode and reasoning effort handling across provider, config, and dashboard, ensuring correct request payload shaping for DeepSeek models.
New Features:
Enhancements:
Tests: