Skip to content

feat: 支持模型级思考参数配置#845

Merged
xerrors merged 12 commits into
xerrors:mainfrom
Yuchuan925:feat/model-request-body-overrides
Jul 23, 2026
Merged

feat: 支持模型级思考参数配置#845
xerrors merged 12 commits into
xerrors:mainfrom
Yuchuan925:feat/model-request-body-overrides

Conversation

@Yuchuan925

@Yuchuan925 Yuchuan925 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

变更描述

为 OpenAI 兼容供应商的单个 chat 模型增加“模型请求参数 JSON”配置,并通过 OpenAI SDK 的 extra_body 合并到最终请求体。

  • 支持模型级保存、回显、修改、清空和缓存同步
  • 模型测试与正式聊天/Agent 调用统一在模型加载入口合并
  • 出于安全考虑采用顶层字段白名单,当前允许:
    • enable_thinking
    • thinking_budget
    • thinking
    • reasoning
    • reasoning_effort
  • thinkingreasoning 子结构不做协议校验,由对应供应商处理
  • 非 OpenAI 兼容供应商及非 chat 模型明确拒绝该配置
  • 同步更新模型管理界面提示、模型配置文档和 changelog

关联 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"
}

具体字段及取值仍以目标供应商和模型的接口文档为准;本功能仅校验顶层白名单,不校验 thinkingreasoning 的子结构。

变更类型

  • 新功能
  • Bug 修复
  • 文档更新
  • 其他

测试

  • 已在 Docker 环境测试
  • 相关功能正常工作

验证结果:

  • 后端核心单元测试:53 passed
  • Ruff 检查和格式检查通过
  • 前端 ESLint 与生产构建通过
  • VitePress 文档构建通过
  • 独立 Reviewer Agent Review:无阻塞问题

真实供应商验证:

  • 供应商:SiliconFlow
  • 模型:Qwen/Qwen3-8B
  • 非流式开启思考:请求包含 enable_thinking=truethinking_budget=128,调用成功并返回正文
  • 非流式关闭思考:请求包含 enable_thinking=false 且不包含预算,调用成功并返回正文
  • 流式开启思考:请求包含 enable_thinking=truethinking_budget=128,调用成功并返回正文
  • 流式关闭思考:请求包含 enable_thinking=false 且不包含预算,调用成功并返回正文

测试过程未记录或输出 API Key。

说明

extra_body 是 OpenAI SDK 的非标准参数入口,其中字段会合并到最终 HTTP 请求体顶层。白名单与 JSON 校验集中在 backend/package/yuxi/models/providers/service.py 的模型配置写入边界;缓存仅搬运已校验配置,Agent 运行时仅负责合并请求体。新增顶层字段时需同步补充测试和模型配置文档。

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Yuchuan925
Yuchuan925 marked this pull request as draft July 23, 2026 08:23
@xerrors

xerrors commented Jul 23, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 32659b7c14

ℹ️ 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".

@xerrors
xerrors marked this pull request as ready for review July 23, 2026 13:17
Copilot AI review requested due to automatic review settings July 23, 2026 13:17
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/intro/model-config.md Outdated
Comment thread web/src/components/model-management/ModelProviderManagePanel.vue Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread backend/package/yuxi/models/providers/service.py
@xerrors
xerrors merged commit d03bdcd into xerrors:main Jul 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants