Fix deepseek 'reasoning_content' error (#8963)

* fix(streaming_handler.py): fix deepseek reasoning content streaming

Fixes https://github.com/BerriAI/litellm/issues/8939

* test(test_streaming_handler.py): add unit test to streaming handle 'is_chunk_non_empty' function

ensures 'reasoning_content' is handled correctly
This commit is contained in:
Krish Dholakia 2025-03-03 14:34:10 -08:00 committed by GitHub
parent b9bddac776
commit 94d28d59e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 106 additions and 8 deletions

View file

@ -360,3 +360,34 @@ def test_o1_parallel_tool_calls(model):
parallel_tool_calls=True,
drop_params=True,
)
def test_openai_chat_completion_streaming_handler_reasoning_content():
from litellm.llms.openai.chat.gpt_transformation import (
OpenAIChatCompletionStreamingHandler,
)
from unittest.mock import MagicMock
streaming_handler = OpenAIChatCompletionStreamingHandler(
streaming_response=MagicMock(),
sync_stream=True,
)
response = streaming_handler.chunk_parser(
chunk={
"id": "e89b6501-8ac2-464c-9550-7cd3daf94350",
"object": "chat.completion.chunk",
"created": 1741037890,
"model": "deepseek-reasoner",
"system_fingerprint": "fp_5417b77867_prod0225",
"choices": [
{
"index": 0,
"delta": {"content": None, "reasoning_content": "."},
"logprobs": None,
"finish_reason": None,
}
],
}
)
assert response.choices[0].delta.reasoning_content == "."