alfadb
a05d9e87c0
feat(billing): 国产模型 thinking-enabled 自动填充 reasoning_effort 默认值
问题: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。
2026-06-16 19:37:31 +08:00
..
2026-06-16 16:58:23 +08:00
2026-06-16 16:55:51 +08:00
2026-05-26 10:49:20 +08:00
2026-02-02 22:13:50 +08:00
2026-06-02 00:46:50 +08:00
2026-04-22 13:19:28 +08:00
2026-05-19 15:27:47 +08:00
2026-05-19 15:27:47 +08:00
2026-05-19 15:27:47 +08:00
2026-06-11 18:55:27 +08:00
2026-06-11 18:55:27 +08:00
2026-06-11 18:55:27 +08:00
2026-05-20 13:25:45 +08:00
2026-06-06 13:05:07 +08:00
2026-06-11 18:55:27 +08:00
2026-04-22 12:30:00 +08:00
2026-06-11 18:55:27 +08:00
2026-06-11 18:55:27 +08:00
2026-05-21 15:19:29 +08:00
2026-05-21 15:19:29 +08:00
2026-06-11 18:55:27 +08:00
2026-05-26 10:49:20 +08:00
2026-05-26 10:49:20 +08:00
2026-06-11 18:55:27 +08:00
2026-04-21 21:44:34 +08:00
2026-04-21 21:44:34 +08:00
2026-04-21 00:21:29 +08:00
2026-05-28 10:03:41 +00:00
2026-06-16 11:41:54 +08:00
2026-05-07 09:14:47 +08:00
2026-05-28 19:39:52 +08:00
2026-05-28 19:39:52 +08:00
2026-03-08 14:12:17 +08:00
2026-03-08 14:12:17 +08:00
2026-05-26 10:49:20 +08:00
2026-06-16 11:41:54 +08:00
2026-06-09 22:46:06 +08:00
2026-02-07 19:04:08 +08:00
2026-06-16 11:41:54 +08:00
2026-03-15 16:21:49 +08:00
2026-05-26 10:49:20 +08:00
2026-06-16 19:37:31 +08:00
2026-02-07 22:14:07 +08:00
2026-03-09 19:55:18 +08:00
2026-06-16 11:41:54 +08:00
2026-01-06 20:31:40 +08:00
2026-06-16 11:41:54 +08:00
2026-05-27 18:00:45 +08:00
2026-02-07 17:12:15 +08:00
2026-04-01 02:20:13 +08:00
2026-06-16 11:41:54 +08:00
2026-06-10 14:16:51 +08:00
2026-02-23 12:45:37 +08:00
2026-02-23 12:45:37 +08:00
2026-05-26 10:49:20 +08:00
2026-05-05 03:26:54 +08:00
2026-02-12 19:01:09 +08:00
2026-06-12 01:47:01 +08:00
2026-05-29 16:21:59 +08:00
2026-04-25 05:26:33 +00:00
2026-06-12 01:47:01 +08:00
2026-03-15 22:13:42 +08:00
2026-06-12 01:47:01 +08:00
2026-06-16 16:55:51 +08:00
2026-05-28 22:44:25 +08:00
2026-05-05 03:26:54 +08:00
2026-06-16 17:59:06 +08:00
2026-06-09 13:57:45 +08:00
2026-06-03 14:18:12 +08:00
2026-06-03 14:18:12 +08:00
2026-06-05 14:00:57 +08:00
2026-06-12 01:47:01 +08:00
2026-06-05 14:00:57 +08:00
2026-06-12 01:47:01 +08:00
2026-05-12 15:21:31 +08:00
2026-06-10 14:16:51 +08:00
2026-05-11 11:17:26 +08:00
2026-05-20 15:12:57 +08:00
2026-05-11 11:17:26 +08:00
2026-05-11 11:17:26 +08:00
2026-04-21 20:36:10 +08:00
2026-06-05 14:00:57 +08:00
2026-05-25 18:16:46 +08:00
2026-05-25 18:16:46 +08:00
2026-05-20 13:25:45 +08:00
2026-06-05 14:00:57 +08:00
2026-06-05 14:00:57 +08:00
2026-04-09 18:14:28 +08:00
2026-06-05 14:00:57 +08:00
2026-05-28 22:44:25 +08:00
2026-05-30 17:52:18 +08:00
2026-05-26 10:49:20 +08:00
2026-03-03 01:05:11 +08:00
2026-05-26 10:49:20 +08:00
2026-06-10 14:16:51 +08:00