[Critical] - Fix ollama_chat reasoning content#20750
Merged
2 commits merged intoBerriAI:litellm_oss_staging_02_09_2026from Feb 10, 2026
Merged
[Critical] - Fix ollama_chat reasoning content#207502 commits merged intoBerriAI:litellm_oss_staging_02_09_2026from
2 commits merged intoBerriAI:litellm_oss_staging_02_09_2026from
Conversation
For ollama_chat models, reasoning context is ignored after 2 consecutive thinking chunks.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryFixed critical bug in Ollama chat streaming where Key changes:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/ollama/chat/transformation.py | Fixed bug where reasoning_content was ignored after 2 consecutive thinking chunks - now all thinking chunks are properly captured |
| tests/test_litellm/llms/ollama/test_ollama_chat_transformation.py | Added comprehensive test coverage for reasoning_content streaming with multiple thinking chunks and edge cases |
Sequence Diagram
sequenceDiagram
participant Client
participant OllamaChatCompletionResponseIterator
participant chunk_parser
participant Delta
Note over OllamaChatCompletionResponseIterator: started_reasoning_content = False<br/>finished_reasoning_content = False
Client->>OllamaChatCompletionResponseIterator: chunk 1 (thinking: "Chunk 1")
OllamaChatCompletionResponseIterator->>chunk_parser: Parse chunk
chunk_parser->>chunk_parser: Check message.thinking != None
chunk_parser->>chunk_parser: Set reasoning_content = "Chunk 1"
chunk_parser->>chunk_parser: Set started_reasoning_content = True
chunk_parser->>Delta: Create delta with reasoning_content
Delta-->>Client: Return chunk with reasoning_content
Client->>OllamaChatCompletionResponseIterator: chunk 2 (thinking: "Chunk 2")
OllamaChatCompletionResponseIterator->>chunk_parser: Parse chunk
chunk_parser->>chunk_parser: Check message.thinking != None
chunk_parser->>chunk_parser: Set reasoning_content = "Chunk 2"
chunk_parser->>Delta: Create delta with reasoning_content
Delta-->>Client: Return chunk with reasoning_content
Client->>OllamaChatCompletionResponseIterator: chunk 3 (thinking: "Chunk 3")
OllamaChatCompletionResponseIterator->>chunk_parser: Parse chunk
chunk_parser->>chunk_parser: Check message.thinking != None
chunk_parser->>chunk_parser: Set reasoning_content = "Chunk 3"
Note right of chunk_parser: OLD BUG: Would skip this<br/>because finished_reasoning_content<br/>was set to True after 2 chunks
chunk_parser->>Delta: Create delta with reasoning_content
Delta-->>Client: Return chunk with reasoning_content
Client->>OllamaChatCompletionResponseIterator: chunk 4 (content: "Answer")
OllamaChatCompletionResponseIterator->>chunk_parser: Parse chunk
chunk_parser->>chunk_parser: Check message.content != None
chunk_parser->>chunk_parser: Set finished_reasoning_content = True
chunk_parser->>chunk_parser: Set content = "Answer"
chunk_parser->>Delta: Create delta with content
Delta-->>Client: Return chunk with content
Contributor
Author
|
@Sameerlite, @ishaan-jaff, @krrishdholakia could you please take a look at this small fix? We really need it in our product. 🙏 |
5adee48
into
BerriAI:litellm_oss_staging_02_09_2026
10 of 13 checks passed
Sameerlite
pushed a commit
that referenced
this pull request
Feb 10, 2026
* Fix ollama_chat reasoning_context. For ollama_chat models, reasoning context is ignored after 2 consecutive thinking chunks. * add test
This was referenced Feb 14, 2026
Closed
Collaborator
|
We use oss staging branch for contributor's PRs, once the branch is stable,
it is merged, fix should be in the latest version
…On Mon, Feb 16, 2026 at 11:33 AM Kowyo ***@***.***> wrote:
*kowyo* left a comment (BerriAI/litellm#20750)
<#20750 (comment)>
hey @DenisStefanAndrei <https://github.com/DenisStefanAndrei>
@krrishdholakia <https://github.com/krrishdholakia>, could you take a
look at why the PR was merged into branch litellm_oss_staging_02_09_2026?
I cannot find the fix in any of the LiteLLM release.
—
Reply to this email directly, view it on GitHub
<#20750 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BXGLABFDBIPZTFNZSZ5R2234MFMR3AVCNFSM6AAAAACUO6XD3SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSMBWGYYTANBYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
For ollama_chat models, reasoning context is ignored after 2 consecutive thinking chunks.
Fixes #20737
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes