Skip to content

feat: AI 助手第三方模型自定义请求体 JSON 与关闭思考快捷填充 - #15

Closed
miantiao-me wants to merge 4 commits into
zoolapp:mainfrom
miantiao-me:feature/ai-model-custom-config
Closed

miantiao-me wants to merge 4 commits into
zoolapp:mainfrom
miantiao-me:feature/ai-model-custom-config

Conversation

@miantiao-me

@miantiao-me miantiao-me commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

功能

在「AI 助手 › OpenAI 兼容接口」配置区域新增自定义请求体 JSON 支持。

自定义请求体

  • 多行输入框,用户可输入任意 JSON 对象
  • 发送 chat/completions 请求时顶层字段合并进请求体,可覆盖 temperature、max_tokens 等参数
  • model、messages、stream 由程序控制,不会被覆盖
  • 非法 JSON 实时提示,不阻断表单

关闭思考快捷按钮

一排按字母排序的厂商按钮,点击把对应的关闭思考参数合并进 JSON 框:

按钮 填入字段 文档
DeepSeek {"thinking": {"type": "disabled"}} DeepSeek API Docs
Gemini {"reasoning_effort": "none"} Gemini OpenAI 兼容接口
GLM {"thinking": {"type": "disabled"}} 智谱开放平台
Kimi {"thinking": {"type": "disabled"}} Kimi 平台文档
OpenAI {"reasoning_effort": "none"} 仅推理模型适用(非推理模型带此字段会 400);OpenAI reasoning
OpenRouter {"reasoning": {"effort": "none"}} OpenRouter reasoning 参数
Qwen {"enable_thinking": false} DashScope / vLLM 部署

只影响 JSON 输入框,不改接口地址和模型名。

改动文件

  • Packages/AIMEKit/Sources/AIMECore/UsageStats.swift — AIMEFeatures + aiExtraJSON
  • Packages/AIMEKit/Sources/AIMEAI/OpenAICompatibleProvider.swift — extraFieldsJSON 参数 + 请求体合并(model/messages/stream 为保留字段)
  • Apps/AIME/AIMEInputController+Polish.swift — 传入 aiExtraJSON
  • Apps/AIMESettings/Views/AIAssistantView.swift — UI
  • Packages/AIMEKit/Tests/AIMEAITests/AITests.swift — 测试(含保留字段回归测试)
  • Packages/AIMEKit/Sources/AIMECore/Resources/catalog.json — appSettings 登记 aiExtraJSON
  • docs/rime-config-reference.md — 配置参考补「AI 助手(AIME 应用设置)」一节
  • CHANGELOG.md / CHANGELOG.en.md — [Unreleased] 条目

- AIMEFeatures 新增 aiExtraJSON 字段,持久化到 features.json
- OpenAICompatibleProvider 支持 extraFieldsJSON,顶层字段合并进请求体
- model/messages 键由程序控制,不可被自定义 JSON 覆盖
- 设置界面新增多行 JSON 输入框,实时合法性提示
- 关闭思考快捷按钮(Claude/DeepSeek/Gemini/GLM/Kimi/OpenAI/Qwen)
@foru17

foru17 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

感谢贡献!自定义请求体这个方向我们很需要。下面这几处改完就可以合并:

  1. 保护 stream:现在只保护了 model 和 messages。如果用户填了 {"stream": true},返回的会是 SSE,解析会失败,报错却是「接口返回的不是 chat/completions 格式」。请把 stream 也加进保护名单,比如 static let reservedKeys: Set = ["model", "messages", "stream"],界面文案同步改。再补一条测试:用户 JSON 里带 stream 和 model 时,请求体里仍是程序设的值。

  2. 「关闭思考」预设要和各家文档一致。按钮写的是关闭思考,点了却不生效或者报 400,会让用户困惑:

    • DeepSeek、Kimi:官方 API 用的是 {"thinking": {"type": "disabled"}},enable_thinking 是 vLLM/Qwen 的写法。
    • Claude:{"reasoning": {"effort": "none"}} 是 OpenRouter 的统一参数,直连 Anthropic 的 OpenAI 兼容接口不认。建议按钮改名为 OpenRouter,或者删掉。
    • OpenAI:minimal 不等于关闭,较新的推理模型支持 "none";非推理模型(gpt-4o / 4.1)带这个字段会直接 400。建议在提示里说明只适用于推理模型。

    麻烦在 PR 描述里给每个预设附上官方文档链接。

  3. 登记:在 CHANGELOG.md / CHANGELOG.en.md 的 [Unreleased] 下补条目,并在 docs/settings-inventory.json 里加上 aiExtraJSON。

另外两个小建议,不阻塞合并:

  • 一行放 7 个按钮,在设置窗口最小宽度下可能放不下。可以跑一下 bash scripts/ui-shots.sh ai,把亮色/暗色 × 默认/最小窗口四张截图贴上来。
  • 用户可以覆盖 temperature、max_tokens,这是有意设计的话,建议在说明文字里写出来。

- model/messages/stream 均不可被自定义 JSON 覆盖,并补回归测试
- DeepSeek、Kimi 改用官方 thinking: {type: disabled} 参数
- Claude 按钮改名 OpenRouter(reasoning.effort 是 OpenRouter 统一参数)
- OpenAI 预设改为 reasoning_effort: none,并提示仅推理模型适用
- CHANGELOG / catalog appSettings / 配置参考文档登记 aiExtraJSON
- 说明文案写明可覆盖 temperature、max_tokens 等
@miantiao-me

Copy link
Copy Markdown
Contributor Author

已按评审意见更新:

  1. stream 保护:model/messages/stream 均为保留字段(OpenAICompatibleProvider.reservedKeys),新增测试 reservedKeysAreNeverOverridden 验证用户 JSON 带 stream/model 时程序值不被覆盖;UI 文案同步。
  2. 预设修正:DeepSeek/Kimi 改用官方 thinking: {"type": "disabled"};Claude 按钮改名 OpenRouter(reasoning.effort 是 OpenRouter 统一参数,直连 Anthropic 兼容接口不认);OpenAI 预设改为 reasoning_effort: "none" 并在悬停提示中说明仅推理模型适用。PR 描述已附各家官方文档链接。
  3. 登记:CHANGELOG(中/英)已补条目;docs/settings-inventory.json 在仓库里不存在,最接近的登记处是 catalog.json 的 appSettings(见 docs/rime-config-reference.md「更新通道(AIME 应用设置)」一段),已在其中登记 aiExtraJSON 并在配置参考文档补了对应小节。如果你说的清单是别的文件,请指出路径,我再补。

另外:说明文字已写明可覆盖 temperature、max_tokens 等参数。scripts/ui-shots.sh ai 在本机跑不出来(Debug 构建启动后窗口不出现,和本次改动无关,main 上同样如此),截图暂时无法附上。

- 校验提示 Label 移到输入框下方(JSON 有效/不合法)
- 输入框改为可滚动的 TextEditor(60–140pt),空时显示示例占位
- 按钮 tooltip 简化为厂商名,说明文案精简为一行
- 长按失效的 .help 替换为简短提示
@foru17 foru17 closed this in 09603c5 Oct 11, 2026
@foru17

foru17 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

感谢 @miantiao-me!已随 09603c5 合入 main(公开仓库是从内部仓库导出的镜像,没法直接在这里点 merge,所以按补丁合入,作者署名保留为你)。

合入时顺带改了几处:

  • 预设按钮的悬停提示原来用的是 preset.title,OpenAI「仅推理模型适用」那句提示显示不出来,已改为 preset.hint;
  • 按钮下方说明改成一句实际用法,颜色调深一档,暗色模式下更清楚;
  • 「JSON 有效,将合并 N 个字段」的 N 不再计入 model / messages / stream;
  • OpenAI 提示写明:reasoning_effort: "none" 从 gpt-5.1 起才支持,更早的推理模型最低只到 minimal。

最小窗口宽度下 7 个按钮一行放得下,亮色和暗色截图都看过了。settings-inventory.json 是内部的历史盘点文件,不需要补,你登记到 catalog.json 是对的。README 也新增了贡献者头像墙,你在里面。会在下个版本发布。

wangsizhu0504 pushed a commit to wangsizhu0504/kime that referenced this pull request Oct 12, 2026
…ributors in README

Settings › AI Assistant › OpenAI-compatible endpoint gains a Custom request body field (top-level fields merged into every request; model, messages and stream stay under program control) and one-click disable-thinking presets for DeepSeek, Gemini, GLM, Kimi, OpenAI, OpenRouter and Qwen. Closes zoolapp#15.

README: contributors section with avatars for code contributors and everyone who filed feedback.

Co-authored-by: 面条 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants