Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions litellm/llms/deepseek/chat/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ def _fill_reasoning_content(self, messages: list[AllMessageValues]) -> list[AllM
stored = provider_fields.get("reasoning_content")
if stored:
patched["reasoning_content"] = stored
cleaned = dict(provider_fields)
cleaned: Final = dict(provider_fields)
cleaned.pop("reasoning_content", None)
patched["provider_specific_fields"] = cleaned
if cleaned:
patched["provider_specific_fields"] = cleaned
else:
patched.pop("provider_specific_fields", None)
else:
litellm.verbose_logger.warning(
"DeepSeek thinking mode: assistant message is missing "
Expand Down Expand Up @@ -211,18 +214,32 @@ def _with_search_results_text_block(self, message: AllMessageValues, content: Se
}
return cast(AllMessageValues, forwarded) # cast-ok: TypedDict spread narrows to dict

@staticmethod
def _is_default_reasoning_model(model: str) -> bool:
try:
model_info: Final = litellm.get_model_info(model=model, custom_llm_provider="deepseek")
return model_info.get("thinking_always_on") is True
except Exception as err: # noqa: BLE001 # unmapped or dynamic model names without metadata
litellm.verbose_logger.debug("Could not check thinking_always_on in model info for %s: %s", model, err)
return False

def _thinking_mode_active(self, model: str, optional_params: dict) -> bool:
"""
Returns True only when thinking mode is actually active for this request:
- model supports reasoning (capability check)
- user explicitly passed thinking={"type": "enabled"} (opt-in check)
"""
if not supports_reasoning(model=model, custom_llm_provider="deepseek"):
return False

thinking: Final = optional_params.get("thinking")
return (
supports_reasoning(model=model, custom_llm_provider="deepseek")
and isinstance(thinking, dict)
and thinking.get("type") == "enabled"
)
if isinstance(thinking, dict):
thinking_type: Final = thinking.get("type")
if thinking_type == "enabled":
return True
if thinking_type == "disabled":
return False
return False

if thinking is not None:
return False

return self._is_default_reasoning_model(model)

@staticmethod
def _drop_unsupported_tools(optional_params: dict) -> dict:
Expand Down
Loading
Loading