fix(dashscope): drop thinking_budget when thinking is disabled

A thinking block of type disabled that still carries budget_tokens now maps to
enable_thinking false alone, instead of a request that both disables thinking
and sets a thinking budget

Co-authored-by: songkuan-zheng <252822057+songkuan-zheng@users.noreply.github.com>
Co-authored-by: songkuan-zheng <songkuan-zheng@users.noreply.github.com>
This commit is contained in:
songkuan-zheng 2026-09-11 12:25:28 +00:00
parent e255b59aa9
commit 0f7ae36521
2 changed files with 2 additions and 1 deletions

View file

@ -27,7 +27,7 @@ def _dashscope_thinking_body(thinking: object, reasoning_effort: object) -> Dash
if isinstance(thinking, dict):
enabled: Final = thinking.get("type") != "disabled"
budget: Final = thinking.get("budget_tokens")
if isinstance(budget, int) and not isinstance(budget, bool):
if enabled and isinstance(budget, int) and not isinstance(budget, bool):
with_budget: Final[DashScopeThinkingBody] = {"enable_thinking": enabled, "thinking_budget": budget}
return with_budget
toggled: Final[DashScopeThinkingBody] = {"enable_thinking": enabled}

View file

@ -207,6 +207,7 @@ class TestDashScopeThinkingParams:
({"type": "enabled", "budget_tokens": 4096}, {"enable_thinking": True, "thinking_budget": 4096}),
({"type": "enabled"}, {"enable_thinking": True}),
({"type": "disabled"}, {"enable_thinking": False}),
({"type": "disabled", "budget_tokens": 4096}, {"enable_thinking": False}),
],
)
def test_thinking_maps_to_enable_thinking_and_budget(self, thinking, expected):