feat: 支持模型级思考参数配置#845
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…body-overrides # Conflicts: # docs/develop-guides/changelog.md
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
There was a problem hiding this comment.
Pull request overview
为 OpenAI 兼容供应商(含 OpenRouter)的单个 chat 模型新增“模型请求参数 JSON”配置能力,并在运行时通过 OpenAI SDK 的 extra_body 合并进最终请求体,从而支持按模型维度配置思考/推理相关参数,同时将该配置纳入模型缓存与管理界面/文档。
Changes:
- 后端:在模型供应商配置写入边界增加
request_body_overrides的白名单与 JSON 合法性校验,并限制仅适用于 provider_type=openai/openrouter 的 chat 模型。 - 运行时:模型加载时将模型级
request_body_overrides合并进调用方的extra_body,并将该字段随模型缓存序列化/反序列化。 - 前端与文档:模型管理界面新增“模型请求参数 JSON”编辑框与提示;补充模型配置文档与 changelog;新增/更新单测覆盖上述行为。
Reviewed changes
Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/components/model-management/ModelProviderManagePanel.vue | 模型配置弹窗新增“模型请求参数 JSON”输入与保存逻辑,并改进 JSON 解析报错信息 |
| docs/intro/model-config.md | 增加模型级思考参数配置说明与字段白名单说明/示例 |
| docs/develop-guides/changelog.md | 记录该功能在 v0.7.2 的变更说明 |
| backend/test/unit/services/test_model_selectors.py | 新增测试:模型级 overrides 与调用方 extra_body 的合并行为 |
| backend/test/unit/services/test_model_provider_service.py | 新增测试:允许字段、非法值、作用域限制(仅 openai/openrouter chat)与 provider_type 变更拦截 |
| backend/test/unit/services/test_model_cache.py | 新增测试:缓存序列化/反序列化携带 request_body_overrides |
| backend/package/yuxi/models/providers/service.py | 实现 request_body_overrides 白名单/JSON 校验与作用域校验,并在更新 provider 配置时强制校验 |
| backend/package/yuxi/models/providers/cache.py | ModelInfo 增加 request_body_overrides 字段并纳入缓存 rebuild/to_dict/from_dict |
| backend/package/yuxi/agents/models.py | load_chat_model 时将 request_body_overrides 合并入 OpenAI SDK extra_body |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 305ad6950d
ℹ️ 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".
变更描述
为 OpenAI 兼容供应商的单个 chat 模型增加“模型请求参数 JSON”配置,并通过 OpenAI SDK 的
extra_body合并到最终请求体。enable_thinkingthinking_budgetthinkingreasoningreasoning_effortthinking、reasoning子结构不做协议校验,由对应供应商处理关联 Project 条目:
https://github.com/users/xerrors/projects/2/views/2?pane=issue&itemId=216418099
界面截图
常见配置示例
SiliconFlow、百炼 DashScope 等使用独立开关和预算字段的兼容接口:
{ "enable_thinking": true, "thinking_budget": 1024 }DeepSeek、Kimi、智谱等提供
thinking结构的兼容接口:{ "thinking": { "type": "enabled" } }OpenRouter:
{ "reasoning": { "effort": "high", "max_tokens": 2048 } }提供 OpenAI 风格推理强度字段的兼容接口:
{ "reasoning_effort": "high" }具体字段及取值仍以目标供应商和模型的接口文档为准;本功能仅校验顶层白名单,不校验
thinking、reasoning的子结构。变更类型
测试
验证结果:
53 passed真实供应商验证:
Qwen/Qwen3-8Benable_thinking=true、thinking_budget=128,调用成功并返回正文enable_thinking=false且不包含预算,调用成功并返回正文enable_thinking=true、thinking_budget=128,调用成功并返回正文enable_thinking=false且不包含预算,调用成功并返回正文测试过程未记录或输出 API Key。
说明
extra_body是 OpenAI SDK 的非标准参数入口,其中字段会合并到最终 HTTP 请求体顶层。白名单与 JSON 校验集中在backend/package/yuxi/models/providers/service.py的模型配置写入边界;缓存仅搬运已校验配置,Agent 运行时仅负责合并请求体。新增顶层字段时需同步补充测试和模型配置文档。