feat(ollama): pass think=false to custom providers when reasoning_effort is none
When a custom/Ollama provider is used and reasoning_effort is set to 'none' (or enabled: false), inject 'think': false into the request extra_body. Ollama does not recognise the OpenRouter-style 'reasoning' extra_body field, so thinking-capable models (Qwen3, etc.) generate <think> blocks regardless of the reasoning_effort setting. This produces empty-response errors that corrupt session state. The fix adds a provider-specific block in _build_api_kwargs() that sets think=false in extra_body whenever self.provider == 'custom' and reasoning is explicitly disabled. Closes #3191
This commit is contained in:
@@ -928,6 +928,7 @@ class TestBuildApiKwargs:
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs["max_tokens"] == 4096
|
||||
|
||||
|
||||
def test_qwen_portal_formats_messages_and_metadata(self, agent):
|
||||
agent.base_url = "https://portal.qwen.ai/v1"
|
||||
agent._base_url_lower = agent.base_url.lower()
|
||||
@@ -983,6 +984,46 @@ class TestBuildApiKwargs:
|
||||
messages = [{"role": "system", "content": "sys"}, {"role": "user", "content": "hi"}]
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs["max_tokens"] == 65536
|
||||
=======
|
||||
def test_ollama_think_false_on_effort_none(self, agent):
|
||||
"""Custom (Ollama) provider with effort=none should inject think=false."""
|
||||
agent.provider = "custom"
|
||||
agent.base_url = "http://localhost:11434/v1"
|
||||
agent._base_url_lower = agent.base_url.lower()
|
||||
agent.reasoning_config = {"effort": "none"}
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs.get("extra_body", {}).get("think") is False
|
||||
|
||||
def test_ollama_think_false_on_enabled_false(self, agent):
|
||||
"""Custom (Ollama) provider with enabled=false should inject think=false."""
|
||||
agent.provider = "custom"
|
||||
agent.base_url = "http://localhost:11434/v1"
|
||||
agent._base_url_lower = agent.base_url.lower()
|
||||
agent.reasoning_config = {"enabled": False}
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs.get("extra_body", {}).get("think") is False
|
||||
|
||||
def test_ollama_no_think_param_when_reasoning_enabled(self, agent):
|
||||
"""Custom provider with reasoning enabled should NOT inject think=false."""
|
||||
agent.provider = "custom"
|
||||
agent.base_url = "http://localhost:11434/v1"
|
||||
agent._base_url_lower = agent.base_url.lower()
|
||||
agent.reasoning_config = {"enabled": True, "effort": "medium"}
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs.get("extra_body", {}).get("think") is None
|
||||
|
||||
def test_non_custom_provider_unaffected(self, agent):
|
||||
"""OpenRouter provider with effort=none should NOT inject think=false."""
|
||||
agent.provider = "openrouter"
|
||||
agent.model = "qwen/qwen3.5-plus-02-15"
|
||||
agent.reasoning_config = {"effort": "none"}
|
||||
messages = [{"role": "user", "content": "hi"}]
|
||||
kwargs = agent._build_api_kwargs(messages)
|
||||
assert kwargs.get("extra_body", {}).get("think") is None
|
||||
|
||||
|
||||
|
||||
class TestBuildAssistantMessage:
|
||||
|
||||
Reference in New Issue
Block a user