fix(ollama): handle dict reasoning_effort and stop forcing think on unsupported efforts

This commit is contained in:
Devin AI 2026-07-25 00:06:13 +00:00
parent 842f32dbaa
commit 696a042e9c
2 changed files with 64 additions and 3 deletions

View file

@ -178,10 +178,12 @@ class OllamaChatConfig(BaseConfig):
if value.get("json_schema") and value["json_schema"].get("schema"):
optional_params["format"] = value["json_schema"]["schema"]
if param == "reasoning_effort" and value is not None:
effort = value.get("effort") if isinstance(value, dict) else value
if model.startswith("gpt-oss"):
optional_params["think"] = value
else:
optional_params["think"] = value in {"low", "medium", "high"}
if effort is not None:
optional_params["think"] = effort
elif effort in {"low", "medium", "high"}:
optional_params["think"] = True
### FUNCTION CALLING LOGIC ###
# Ollama 0.4+ supports native tool calling - pass tools directly
# and let Ollama handle model capability detection

View file

@ -906,3 +906,62 @@ class TestOllamaToolCallTransformation:
assert tool_msg["content"] == "Sunny, 72°F"
assert "tool_call_id" in tool_msg, "tool_call_id must be forwarded to Ollama"
assert tool_msg["tool_call_id"] == "call_abc123"
class TestOllamaReasoningEffortMapping:
"""
Issue: https://github.com/BerriAI/litellm/issues/34574
"""
def test_dict_reasoning_effort_does_not_crash(self):
optional_params = get_optional_params(
model="ollama_chat/qwen3:14b",
reasoning_effort={"effort": "medium", "summary": "auto"},
custom_llm_provider="ollama_chat",
)
assert optional_params["think"] is True
def test_dict_reasoning_effort_without_effort_key_is_ignored(self):
optional_params = get_optional_params(
model="ollama_chat/qwen3:14b",
reasoning_effort={"summary": "auto"},
custom_llm_provider="ollama_chat",
)
assert "think" not in optional_params
def test_unsupported_effort_does_not_force_thinking(self):
optional_params = get_optional_params(
model="ollama_chat/qwen3-coder:30b",
reasoning_effort="none",
custom_llm_provider="ollama_chat",
)
assert "think" not in optional_params
def test_gpt_oss_forwards_effort_level(self):
config = OllamaChatConfig()
assert config.map_openai_params(
non_default_params={"reasoning_effort": {"effort": "high"}},
optional_params={},
model="gpt-oss:20b",
drop_params=False,
) == {"think": "high"}
assert config.map_openai_params(
non_default_params={"reasoning_effort": "low"},
optional_params={},
model="gpt-oss:20b",
drop_params=False,
) == {"think": "low"}
def test_string_effort_enables_thinking(self):
optional_params = get_optional_params(
model="ollama_chat/qwen3:14b",
reasoning_effort="high",
custom_llm_provider="ollama_chat",
)
assert optional_params["think"] is True