diff --git a/litellm/llms/dashscope/chat/transformation.py b/litellm/llms/dashscope/chat/transformation.py index 304be9435da..459369d4c60 100644 --- a/litellm/llms/dashscope/chat/transformation.py +++ b/litellm/llms/dashscope/chat/transformation.py @@ -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} diff --git a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py index 395bfe61cbf..fbc2b0b47a7 100644 --- a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py +++ b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py @@ -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):