litellm/tests/test_litellm/llms/ollama
devin-ai-integration[bot] ca86898633
fix(ollama): read the JSON thinking field on non-streaming completions (#42838)
* fix(ollama): read the JSON thinking field on non-streaming completions

Ollama's /api/generate returns reasoning in a top-level `thinking` field, but
the completion transport only looked for inline <think> tags. reasoning_content
was therefore always null, and a model that spent its whole turn reasoning
returned an empty assistant message with tokens billed.

Port the precedence the ollama_chat transport already uses: the field wins and
inline tags stay the fallback. Applied to both non-streaming paths, including
the JSON-mode text fallback. The two fields are read through a small validated
model rather than off the untyped JSON, so absent and explicitly null
`response` stay distinct exactly as before.

* fix(ollama): keep the thinking field on JSON-mode completions

The first pass read `thinking` for plain replies and for JSON-mode text that
failed to parse, but the three JSON-mode branches that succeed still dropped
it: an empty `response`, a valid JSON object, and a function-call shaped one.
A model that spent its whole turn reasoning under `format: json` therefore
still came back blank with the tokens billed.

Carry the field on all three, type the new test helper's parameters, and cover
the null and malformed `response` fallbacks.

---------

Co-authored-by: Pawan-Shahane <shahanepawan511@gmail.com>
2026-09-23 18:26:02 -07:00
..
test_ollama_chat_transformation.py fix(streaming): keep an explicit provider prompt_tokens=0 or completion_tokens=0 in streamed usage 2026-09-21 14:01:08 -07:00
test_ollama_completion_transformation.py fix(ollama): read the JSON thinking field on non-streaming completions (#42838) 2026-09-23 18:26:02 -07:00
test_ollama_embedding.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_ollama_model_info.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00