From 7824dc07d3802071932dc6495368bf61233f6acd Mon Sep 17 00:00:00 2001 From: Milan Date: Thu, 11 Jun 2026 23:28:36 +0300 Subject: [PATCH] chore(deepseek): trim comments to essentials Co-authored-by: Cursor --- litellm/llms/deepseek/chat/transformation.py | 27 +++++-------------- .../chat/test_deepseek_chat_transformation.py | 13 ++------- .../test_deepseek_completion.py | 8 +----- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/litellm/llms/deepseek/chat/transformation.py b/litellm/llms/deepseek/chat/transformation.py index c8ece202841..44abe5c6878 100644 --- a/litellm/llms/deepseek/chat/transformation.py +++ b/litellm/llms/deepseek/chat/transformation.py @@ -49,14 +49,12 @@ class DeepSeekChatConfig(OpenAIGPTConfig): thinking_value = optional_params.pop("thinking", None) reasoning_effort = optional_params.pop("reasoning_effort", None) - # Handle thinking parameter - accept {"type": "enabled"} and - # {"type": "disabled"} (the latter opts out of V4's default-on thinking) + # DeepSeek only accepts the `type` key, ignore budget_tokens if thinking_value is not None: if isinstance(thinking_value, dict) and thinking_value.get("type") in ( "enabled", "disabled", ): - # DeepSeek only accepts the `type` key, ignore budget_tokens optional_params["thinking"] = {"type": thinking_value["type"]} # Handle reasoning_effort - map to thinking enabled @@ -138,17 +136,9 @@ class DeepSeekChatConfig(OpenAIGPTConfig): def _thinking_mode_active(self, model: str, optional_params: dict) -> bool: """ - Returns True when thinking mode may be active for this request. - - DeepSeek V4 models enable thinking BY DEFAULT (no `thinking` param - required - https://api-docs.deepseek.com/guides/thinking_mode), so any - reasoning-capable model counts unless the user explicitly disabled - thinking. Same approach as the Moonshot reasoning fix - (litellm/llms/moonshot/chat/transformation.py). - - Injecting `reasoning_content` when thinking is NOT active is harmless: - the DeepSeek API ignores the field in non-thinking requests (verified - against the live API, including thinking={"type": "disabled"}). + DeepSeek V4 enables thinking by default, so any reasoning-capable model + counts unless thinking is explicitly disabled. The API ignores + `reasoning_content` in non-thinking requests, so over-injecting is safe. """ if (optional_params.get("thinking") or {}).get("type") == "disabled": return False @@ -163,13 +153,8 @@ class DeepSeekChatConfig(OpenAIGPTConfig): headers: dict, ) -> dict: """ - Ensures `reasoning_content` is forwarded on assistant messages for - multi-turn thinking-mode conversations (issue #28045). - - Only runs when thinking mode is actually active - guarded by both - supports_reasoning() (model capability) and optional_params["thinking"] - (user explicitly enabled it), preventing spurious injection on models - like deepseek-v3.2 that support thinking as opt-in but not always-on. + Forwards `reasoning_content` on assistant messages for multi-turn + thinking-mode conversations. """ if self._thinking_mode_active(model=model, optional_params=optional_params): messages = self._fill_reasoning_content(messages) diff --git a/tests/litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py b/tests/litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py index ba3dfed2b60..d74fb533e1a 100644 --- a/tests/litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py +++ b/tests/litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py @@ -168,8 +168,7 @@ class TestDeepSeekThinkingParams: assert "thinking" not in result def test_map_thinking_disabled_passed_through(self): - """thinking={"type": "disabled"} must be forwarded so users can opt out - of DeepSeek V4's default-on thinking mode.""" + """thinking={"type": "disabled"} is forwarded (opt-out of V4 default thinking).""" result = self.config.map_openai_params( non_default_params={"thinking": {"type": "disabled"}}, optional_params={}, @@ -181,11 +180,7 @@ class TestDeepSeekThinkingParams: class TestDeepSeekV4DefaultThinkingMode: - """ - DeepSeek V4 models run in thinking mode BY DEFAULT and require - `reasoning_content` to be passed back on assistant messages - (https://github.com/BerriAI/litellm/issues/26395). - """ + """DeepSeek V4 default-on thinking mode / reasoning_content pass-back.""" def setup_method(self): self.config = DeepSeekChatConfig() @@ -221,10 +216,6 @@ class TestDeepSeekV4DefaultThinkingMode: ) def test_reasoning_capable_models_active_by_default(self): - """Any reasoning-capable DeepSeek model counts as potentially - thinking-mode (V4 enables thinking by default). Injection is harmless - when thinking is not actually active: the live API ignores - reasoning_content in non-thinking requests.""" assert self.config._thinking_mode_active( model="deepseek-v3.2", optional_params={} ) diff --git a/tests/llm_translation/test_deepseek_completion.py b/tests/llm_translation/test_deepseek_completion.py index e574b7e1f63..d3cb913625a 100644 --- a/tests/llm_translation/test_deepseek_completion.py +++ b/tests/llm_translation/test_deepseek_completion.py @@ -234,13 +234,7 @@ def test_deepseek_fill_reasoning_content_multiturn(): def test_deepseek_fill_reasoning_content_guard_in_transform_request(): """ _fill_reasoning_content runs for any reasoning-capable DeepSeek model - unless thinking is explicitly disabled. - - DeepSeek V4 enables thinking mode BY DEFAULT (no `thinking` param - required), so the guard cannot rely on an explicit opt-in (issue #26395). - Injecting reasoning_content when thinking is not actually active is - harmless: the DeepSeek API ignores the field in non-thinking requests - (verified against the live API, including thinking={"type": "disabled"}). + unless thinking is explicitly disabled (V4 enables thinking by default). """ from litellm.llms.deepseek.chat.transformation import DeepSeekChatConfig