From 59b0337ff006d00f87579f8b65077726404d022a Mon Sep 17 00:00:00 2001 From: Dave Fobare Date: Fri, 15 May 2026 16:27:40 -0400 Subject: [PATCH] Respect explicit Ollama think setting --- SourceCode/shared_tools/ollama_client.py | 2 +- tests/test_ollama_wait_for_available.py | 46 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/SourceCode/shared_tools/ollama_client.py b/SourceCode/shared_tools/ollama_client.py index fc0f679..31300b9 100755 --- a/SourceCode/shared_tools/ollama_client.py +++ b/SourceCode/shared_tools/ollama_client.py @@ -202,7 +202,7 @@ def chat( }, } effective_think = think - if self._is_reasoning_model(model_name): + if effective_think is None and self._is_reasoning_model(model_name): effective_think = True if effective_think is not None: payload["think"] = effective_think diff --git a/tests/test_ollama_wait_for_available.py b/tests/test_ollama_wait_for_available.py index 45af9ac..1d7fca9 100644 --- a/tests/test_ollama_wait_for_available.py +++ b/tests/test_ollama_wait_for_available.py @@ -8,6 +8,52 @@ class OllamaWaitForAvailableTests(unittest.TestCase): + def test_chat_auto_enables_thinking_for_reasoning_models_by_default(self) -> None: + client = OllamaClient() + seen_payloads: list[dict] = [] + + def fake_stream(payload: dict, *, timeout: int, idle_timeout_sec: int) -> str: + seen_payloads.append(dict(payload)) + return "ok" + + client._post_json_stream_chat = MagicMock(side_effect=fake_stream) + + out = client.chat("qwen3:8b", "system", "user") + + self.assertEqual(out, "ok") + self.assertEqual(seen_payloads[0].get("think"), True) + + def test_chat_respects_explicit_false_think_for_reasoning_models(self) -> None: + client = OllamaClient() + seen_payloads: list[dict] = [] + + def fake_stream(payload: dict, *, timeout: int, idle_timeout_sec: int) -> str: + seen_payloads.append(dict(payload)) + return "ok" + + client._post_json_stream_chat = MagicMock(side_effect=fake_stream) + + out = client.chat("qwen3:14b", "system", "user", think=False, num_predict=48) + + self.assertEqual(out, "ok") + self.assertEqual(seen_payloads[0].get("think"), False) + self.assertEqual(seen_payloads[0]["options"]["num_predict"], 48) + + def test_chat_respects_explicit_true_think_for_non_reasoning_models(self) -> None: + client = OllamaClient() + seen_payloads: list[dict] = [] + + def fake_stream(payload: dict, *, timeout: int, idle_timeout_sec: int) -> str: + seen_payloads.append(dict(payload)) + return "ok" + + client._post_json_stream_chat = MagicMock(side_effect=fake_stream) + + out = client.chat("qwen2.5-coder:7b", "system", "user", think=True) + + self.assertEqual(out, "ok") + self.assertEqual(seen_payloads[0].get("think"), True) + def test_wait_for_available_uses_tags_and_show_not_chat(self) -> None: client = OllamaClient() client._get_json = MagicMock(return_value={"models": [{"name": "qwen3:8b"}]})