mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(ollama): process both thinking and content in same streaming chunk (#26098)
This commit is contained in:
parent
db687bfeca
commit
764c128120
2 changed files with 25 additions and 1 deletions
|
|
@ -510,7 +510,7 @@ class OllamaChatCompletionResponseIterator(BaseModelResponseIterator):
|
|||
if chunk["message"].get("thinking") is not None:
|
||||
reasoning_content = chunk["message"].get("thinking")
|
||||
self.started_reasoning_content = True
|
||||
elif chunk["message"].get("content") is not None:
|
||||
if chunk["message"].get("content") is not None:
|
||||
if (
|
||||
self.started_reasoning_content
|
||||
and not self.finished_reasoning_content
|
||||
|
|
|
|||
|
|
@ -694,6 +694,30 @@ class TestOllamaReasoningContentStreaming:
|
|||
# reasoning_content is not set when there's no thinking in the chunk
|
||||
assert getattr(result2.choices[0].delta, "reasoning_content", None) is None
|
||||
|
||||
def test_thinking_and_content_in_same_chunk(self):
|
||||
"""
|
||||
Test that a chunk containing both thinking and content preserves both fields.
|
||||
"""
|
||||
iterator = OllamaChatCompletionResponseIterator(
|
||||
streaming_response=iter([]),
|
||||
sync_stream=True,
|
||||
)
|
||||
|
||||
chunk = {
|
||||
"model": "deepseek-r1",
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"thinking": "Let me reason first.",
|
||||
"content": "Final answer.",
|
||||
},
|
||||
"done": False,
|
||||
}
|
||||
|
||||
result = iterator.chunk_parser(chunk)
|
||||
|
||||
assert result.choices[0].delta.reasoning_content == "Let me reason first."
|
||||
assert result.choices[0].delta.content == "Final answer."
|
||||
|
||||
def test_think_tags_in_content(self):
|
||||
"""
|
||||
Test that <think> tags embedded in content are properly parsed.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue