Skip to content

[Feature] 希望OpenAI 兼容渠道的思考字段名(reasoning key)支持自定义/可配置 #9783

Description

@Kisaragi911

Feature Description

目前 AstrBot 在 openai_source.py 中将思考内容字段名硬编码为:

self.reasoning_key = "reasoning_content"

_extract_reasoning_content() 仅通过该字段名从响应中提取思考内容。然而不同上游/中转渠道对思考内容的字段命名并不统一:

  • Moonshot / DeepSeek / 阿里百炼等:reasoning_content
  • OpenRouter 及部分基于 OpenRouter 协议的中转渠道(如 cline-pass 等):reasoning(并附带 reasoning_details 数组)
  • AstrBot 自己的 groq_source.pyopenrouter_source.py 已经通过覆盖 reasoning_key = "reasoning" 做了内部适配,说明项目已经意识到这个字段存在"方言",但通用 openai_chat_completion 类型渠道无法享受这个能力

实际场景(已验证)

通过 new-api 接入 cline-pass 渠道的 kimi-k3,上游实际返回结构为:

{
  "message": {
    "content": "...正文...",
    "reasoning": "...思考内容...",
    "reasoning_details": [{"type": "reasoning.text", "text": "..."}]
  }
}

由于字段名为 reasoning 而非 reasoning_content,AstrBot 完全无法识别思考内容(同一 API 在其他前端可正常显示思考)。new-api 侧的「think 转 content」开关只能在非流式下通过 `` 标签兜底,流式路径下 AstrBot 无对应解析逻辑,依然丢失。

Use Case

期望方案(任一即可)

  1. 渠道配置项:在 openai_chat_completion 类型 provider 的配置中增加可选字段,如 reasoning_key,默认 reasoning_content,允许用户按渠道填写 reasoning 等别名;
  2. 多字段名兼容_extract_reasoning_content() 内置常见字段名候选列表(如 ["reasoning_content", "reasoning"]),按优先级自动探测;
  3. 流式兜底为流式路径补充与非流式一致的 正则提取,作为字段名不匹配时的最后手段。

方案 1 对用户最灵活,改动也最小(reasoning_key 已实例化,只需从 provider_config 读取覆盖默认值)。

相关代码位置

  • astrbot/core/provider/sources/openai_source.pyself.reasoning_key = "reasoning_content"(约 399 行)、_extract_reasoning_content()(约 700 行)
  • astrbot/core/provider/sources/groq_source.pyopenrouter_source.py:已有 reasoning_key = "reasoning" 的覆盖先例

Checklist

  • I have searched the Issue list for related features and confirmed this feature idea has never been proposed.
  • The feature I am suggesting is related to AstrBot itself, not to a specific plugin.
  • I have read and agree to the project's Code of Conduct.
  • (Optional) I am willing to submit a PR to help implement this feature.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions