Repository navigation
fix: do not prefix Ollama replies with <think>None</think> - #2619
pcbeingused333 wants to merge 1 commit into
Conversation
Message.thinking is Optional and defaults to None in ollama>=0.5, so hasattr is always true and generate stringified that None into every reply. Skip the prefix when thinking is empty, as generate_stream does.
🤖 Open Code ReviewTarget: PR #2619 ✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). Generated by cloud-assistant via Open Code Review. |
✅ Automated Test Results: PASSEDRequired tests passed (3/3 executed, 0 skipped). Duration: 15s [advisory, non-gating] AI-generated tests on branch test/auto-gen-860edb8e0565fb51-20261117094923: 36/36 passed — these do NOT affect the PR verdict; review the branch manually. Branch: Tested source: |
Description
OllamaLLM.generateprefixes every reply with the literal text<think>None</think>when the model returns no thinking.Root cause.
ollama0.5 (the pinned range) declaresMessage.thinkingas optional with defaultNone, so the attribute is always present.generatetreatedhasattr(response.message, "thinking")as "there is thinking" and interpolated the value, soNonebecomes the charactersNone.remove_think_prefixdefaults toFalse, so callers with the default config receive the prefix.generate_streamalready skips empty thinking.Fix. Build the
<think>wrapper only whenthinkingis non-empty. A missing attribute,Noneand""produce no prefix; a real thinking string is still wrapped unchanged.Related Issue (Required): none filed; this is a small bug fix, which CONTRIBUTING.md allows as a direct PR.
Type of change
How Has This Been Tested?
tests/llms/test_ollama.py::test_generate_does_not_stringify_none_thinkingbuilds anollama.Messagewith only role and content (sothinkingisNone), mocksclient.chat, and assertsgeneratereturns"Hello". It fails onmainwith<think>None</think>Hello. The existing tests still check that a real thinking string is wrapped.Reproduction:
pytest tests/llms/test_ollama.pyChecklist
This change was prepared with the help of an AI assistant.