Skip to content

OpenAI 兼容路径不支持 thinking 配置,导致 DeepSeek V4 Pro 思考 Token 耗尽 max_tokens 预算 #74

Description

@taekchef

问题描述

使用 AionRS 连接 DeepSeek V4 Pro 模型时,模型会长时间思考但最终可能无法产生工具调用(返回 finish_reason: "length"),表现为"一直在思考但不执行任务"。

根因分析

1. OpenAI provider 无法发送 thinking 配置

DeepSeek V4 Pro 默认 thinking: {type: "enabled"},思考模式始终开启。但 AionRS 的 OpenAI 兼容路径:

  • 只发送 reasoning_effort,不发送 thinking 对象
  • 代码位置:crates/aion-providers/src/openai.rs:250-266build_body 方法
// 当前只发送了 reasoning_effort(第 262-264 行)
if let Some(effort) = &request.reasoning_effort {
    body["reasoning_effort"] = json!(effort);
}
// 缺少:body["thinking"] = json!({"type": "enabled"});

对比 Anthropic provider(anthropic.rs:84-85)是发送了 thinking 配置的。

2. supports_thinking 对 OpenAI 路径固定为 false

crates/aion-config/src/compat.rs:99openai_defaults()supports_thinking: Some(false),导致即使用户通过 SetConfig 协议发送了 thinking + thinking_budget,也会被 engine.rs:284 拦截:

if !self.compat.supports_thinking() {
    changes.push("thinking: not supported by current provider".to_string());
}

3. 默认 max_tokens 偏小

crates/aion-config/src/config.rs:226default_max_tokens() 返回 8192。DeepSeek V4 Pro 的思考 token 和输出 token 共享这个配额,模型可能在思考阶段就消耗了 6000-7000 token,剩余不足以产生工具调用。

4. 实际影响验证

从用户会话数据看:

  • DeepSeek V4 Pro:151 条消息,总输出 28K token,平均每轮仅 ~186 token(大量被思考消耗)
  • DeepSeek V4 Flash:68 条消息,总输出 75K token,平均每轮 ~1108 token(Flash 思考开销小)

AionRS 启动命令中缺少 --max-tokens 参数:

aionrs --json-stream --provider openai --model deepseek-v4-pro --base-url https://api.deepseek.com

建议修复

  1. OpenAI provider 支持发送 thinking 配置 — 当 request.thinkingSome(Enabled { budget_tokens }) 时,在请求体中添加 "thinking": {"type": "enabled"};为 Some(Disabled) 时添加 "thinking": {"type": "disabled"}
  2. 更新 supports_thinking 机制 — 不应全局写死为 false,应允许用户/模型级别的 override,或者至少让 DeepSeek 等支持 thinking 的 OpenAI 兼容模型能配置
  3. 提高默认 max_tokens — 对于已知的 thinking 模型,默认值至少应该设到 16384 或更高
  4. 支持 --max-tokens 命令行参数 — AionUI 等宿主客户端可以通过此参数覆盖默认值

环境信息

  • AionRS 版本:v0.1.15
  • 模型:deepseek-v4-pro
  • 运行方式:通过 AionUI 以 --json-stream 模式启动

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions