mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-24 08:39:29 +00:00
问题:Kimi/GLM/MiniMax 等国产 LLM 协议层只有 thinking on/off 开关,没有 reasoning_effort 档位概念。客户端启用 thinking 后 usage_log.reasoning_effort 长期为 NULL,无法在用量分析里区分 'thinking 开启' 与 'thinking 关闭'。 方案:仅在 'thinking 启用 + 上游属于 passback-required 国产模型 + 客户端 未明确指定 effort' 三者同时成立时,给 usage_log.reasoning_effort 写默认值 'high'(与 DeepSeek thinking-enabled 默认 effort 一致)。 设计原则: 1. **白名单**:仅 ResolveThinkingProtocol == PassbackRequired 集合内, 且排除原生支持 effort 的 DeepSeek(避免覆盖客户端意图)。 2. **fail-open**:客户端显式传 effort 时永远不覆盖。 3. **未来兼容**:如 Kimi 后续加入真 effort 档位,客户端开始发 effort, guard (3) 自动让出,本逻辑变 no-op。 实现: - gateway_request.go: 加 DefaultEffortForThinkingEnabled (按模型白名单) + OpenAIBodyHasThinkingEnabled (检测 OpenAI 协议 body 里的 thinking.type) + ApplyThinkingEnabledFallback (包装现有 extractor 的 nil-then-default 逻辑) - gateway_handler.go: Anthropic 路径两处(主 + retry)对称补充 - OpenAI 路径全覆盖:openai_gateway_service.go (passthrough + non-passthrough) + openai_gateway_chat_completions_raw.go + openai_gateway_responses_chat_fallback.go + openai_ws_http_bridge.go + openai_ws_forwarder.go - 跨协议路径:gateway_forward_as_chat_completions.go (CC client → Anthropic upstream) + gateway_forward_as_responses.go (Responses client → Anthropic upstream) + gemini_chat_completions_compat_service.go (一致性保持) 未覆盖:openai_ws_v2_passthrough_adapter.go 两处。原因:该 adapter 持有的是 session-level 客户端原始 model,没有 *Account 句柄无法走 GetMappedModel。 WS v2 当前对国产模型场景不重要(pi 调用 Kimi/GLM/MiniMax 走 sync HTTP), 留待后续如果出现 WS v2 + 国产模型用例时单独处理。 测试: - TestDefaultEffortForThinkingEnabled (14 用例):覆盖 Kimi/GLM/MiniMax 大小写、 Qwen thinking 变体、DeepSeek 排除、Claude/GPT/Gemini 不命中。 - TestOpenAIBodyHasThinkingEnabled (8 用例):covers enabled/adaptive/disabled、 大小写、空 body、缺字段、invalid JSON fail-safe。 - TestApplyThinkingEnabledFallback (9 用例):现有 effort 不覆盖、nil + 启用 + passback → high、nil + disabled → nil、nil + 启用 + 排除模型 → nil。