fix: thinking mode was never actually disabled (extra_body bug)

_add_thinking_mode set data["extra_body"]={"enable_thinking": False},
but extra_body is an OpenAI Python SDK convention that gets unwrapped
to top-level by the SDK. This project sends requests via httpx, so
extra_body was sent as a literal nested key that DashScope ignores —
qwen3.6-plus kept thinking ON, wasting 96% of output tokens on
reasoning (measured: 0.54K reasoning / 0.56K output) and inflating
a 3-min translation to 24-min.

Fix: when the field is extra_body (aliyuncs/google providers), merge
its dict into the top-level request body instead of nesting it.
This commit is contained in:
2026-07-27 18:05:53 +08:00
parent 746425528f
commit d252ac5de3

View File

@@ -570,10 +570,13 @@ class Agent:
if thinking_mode_result is None:
return
field_thinking, val_enable, val_disable = thinking_mode_result
if self.thinking == "enable":
data[field_thinking] = val_enable
elif self.thinking == "disable":
data[field_thinking] = val_disable
value = val_enable if self.thinking == "enable" else val_disable
# extra_body 是 OpenAI SDK 约定;本项目用 httpx 直接发请求,
# 必须把里面的字段提到顶层DashScope / GLM 等才会识别。
if field_thinking == "extra_body" and isinstance(value, dict):
data.update(value)
else:
data[field_thinking] = value
def _normalize_mt_lang(self, lang: str | None) -> str | None:
if lang is None: