From bdd3e30284dc00a9c715ef80ed71119120ef2e36 Mon Sep 17 00:00:00 2001 From: X-iZhang Date: Sat, 7 Mar 2026 18:44:11 +0000 Subject: [PATCH] feat(ollama): enable reasoning by default for Ollama models and update tests --- EvoScientist/llm/models.py | 4 ++++ tests/test_llm.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/EvoScientist/llm/models.py b/EvoScientist/llm/models.py index 69aed3d..7ec7ed1 100644 --- a/EvoScientist/llm/models.py +++ b/EvoScientist/llm/models.py @@ -137,6 +137,10 @@ def _apply_auto_config( if provider == "google-genai": kwargs.setdefault("include_thoughts", True) + # Ollama: separate reasoning content from response for thinking models + if provider == "ollama" and "reasoning" not in kwargs: + kwargs["reasoning"] = True + def get_chat_model( model: str | None = None, diff --git a/tests/test_llm.py b/tests/test_llm.py index 91a39fc..f4800b0 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -282,8 +282,8 @@ class TestOllamaProvider: assert "base_url" not in call_kwargs @patch("EvoScientist.llm.models.init_chat_model") - def test_no_thinking_for_ollama(self, mock_init, monkeypatch): - """Test that thinking/reasoning is not auto-enabled for Ollama models.""" + def test_reasoning_auto_enabled_for_ollama(self, mock_init, monkeypatch): + """Test that reasoning is auto-enabled for Ollama models.""" mock_init.return_value = "mock_model" monkeypatch.delenv("OLLAMA_BASE_URL", raising=False) @@ -291,7 +291,18 @@ class TestOllamaProvider: call_kwargs = mock_init.call_args[1] assert "thinking" not in call_kwargs - assert "reasoning" not in call_kwargs + assert call_kwargs["reasoning"] is True + + @patch("EvoScientist.llm.models.init_chat_model") + def test_reasoning_not_overridden_for_ollama(self, mock_init, monkeypatch): + """Test that explicit reasoning=False is not overridden for Ollama.""" + mock_init.return_value = "mock_model" + monkeypatch.delenv("OLLAMA_BASE_URL", raising=False) + + get_chat_model("llama3.1:8b", provider="ollama", reasoning=False) + + call_kwargs = mock_init.call_args[1] + assert call_kwargs["reasoning"] is False def test_no_static_registry_entries(self): """Test that Ollama has no static registry entries (models detected dynamically)."""