mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
Merge a3ac6f6b73 into e768ad55ce
This commit is contained in:
commit
148be912ad
2 changed files with 49 additions and 0 deletions
|
|
@ -59,6 +59,14 @@ class DeepSeekChatConfig(OpenAIGPTConfig):
|
|||
elif reasoning_effort is not None:
|
||||
optional_params["thinking"] = {"type": "disabled" if reasoning_effort == "none" else "enabled"}
|
||||
|
||||
if (
|
||||
model.removeprefix("deepseek/").startswith(("deepseek-v4-", "deepseek-flash"))
|
||||
and not (isinstance(thinking_value, dict) and thinking_value.get("type") == "disabled")
|
||||
and isinstance(reasoning_effort, str)
|
||||
and reasoning_effort != "none"
|
||||
):
|
||||
return {**optional_params, "reasoning_effort": reasoning_effort} # mutable-ok: adapters mutate this dict
|
||||
|
||||
return optional_params
|
||||
|
||||
def _fill_reasoning_content(self, messages: list[AllMessageValues]) -> list[AllMessageValues]:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
from typing import Final
|
||||
|
||||
import pytest
|
||||
|
||||
from litellm.llms.deepseek.chat.transformation import DeepSeekChatConfig
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model", ("deepseek-flash", "deepseek-v4-pro", "deepseek-v4-flash-vision-exp", "deepseek/deepseek-v4-flash")
|
||||
)
|
||||
@pytest.mark.parametrize("effort", ("minimal", "low", "medium", "high", "xhigh", "max", "ultra"))
|
||||
@pytest.mark.parametrize("thinking", (None, "enabled"))
|
||||
def test_v4_keeps_requested_effort_with_enabled_thinking(model: str, effort: str, thinking: str | None) -> None:
|
||||
params: Final = {"reasoning_effort": effort, **({"thinking": {"type": thinking}} if thinking else {})}
|
||||
result: Final = DeepSeekChatConfig().map_openai_params(params, {}, model, False)
|
||||
assert result == {"thinking": {"type": "enabled"}, "reasoning_effort": effort}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"thinking,effort,expected",
|
||||
(
|
||||
(None, None, {}),
|
||||
(None, "none", {"thinking": {"type": "disabled"}}),
|
||||
("disabled", "low", {"thinking": {"type": "disabled"}}),
|
||||
("disabled", "max", {"thinking": {"type": "disabled"}}),
|
||||
("enabled", "none", {"thinking": {"type": "enabled"}}),
|
||||
("enabled", None, {"thinking": {"type": "enabled"}}),
|
||||
),
|
||||
)
|
||||
def test_v4_retains_explicit_thinking_precedence(
|
||||
thinking: str | None, effort: str | None, expected: dict[str, dict[str, str]]
|
||||
) -> None:
|
||||
params: Final = {"reasoning_effort": effort, **({"thinking": {"type": thinking}} if thinking else {})}
|
||||
result: Final = DeepSeekChatConfig().map_openai_params(params, {}, "deepseek-flash", False)
|
||||
assert result == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", ("deepseek-chat", "deepseek-reasoner", "deepseek/deepseek-reasoner"))
|
||||
def test_legacy_models_retain_toggle_only_mapping(model: str) -> None:
|
||||
result: Final = DeepSeekChatConfig().map_openai_params({"reasoning_effort": "low"}, {}, model, False)
|
||||
assert result == {"thinking": {"type": "enabled"}}
|
||||
Loading…
Add table
Reference in a new issue