This commit is contained in:
jesco 2026-08-27 17:30:25 -05:00 committed by GitHub
commit fd10908d4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 6 deletions

View file

@ -204,12 +204,7 @@ async def convert_to_streaming_response_async(
t["index"] = index
pydantic_tool_calls.append(ChatCompletionDeltaToolCall(**t))
choice["message"]["tool_calls"] = pydantic_tool_calls
delta = Delta(
content=choice["message"].get("content", None),
role=choice["message"]["role"],
function_call=choice["message"].get("function_call", None),
tool_calls=choice["message"].get("tool_calls", None),
)
delta = Delta(**choice["message"])
finish_reason = choice.get("finish_reason", None)
if finish_reason is None:

View file

@ -2002,6 +2002,60 @@ class TestConvertToStreamingResponseAsync:
assert chunks[-1].choices[0].finish_reason == "stop"
assert chunks[-1].usage.prompt_tokens == 3
def test_preserves_reasoning_fields(self):
import asyncio
from litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (
convert_to_streaming_response_async,
)
thinking_blocks = [
{
"type": "thinking",
"thinking": "cached reasoning",
"signature": "sig-cache",
}
]
response_object = {
"id": "msg_async_reasoning_cache",
"model": "claude-3",
"created": 1700000000,
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Final answer",
"role": "assistant",
"reasoning_content": "cached reasoning",
"thinking_blocks": thinking_blocks,
},
}
],
}
async def run():
return [
chunk
async for chunk in convert_to_streaming_response_async(
response_object=response_object
)
]
chunks = asyncio.run(run())
assert (
"".join(c.choices[0].delta.content or "" for c in chunks) == "Final answer"
)
assert chunks[0].choices[0].delta.reasoning_content == "cached reasoning"
assert chunks[0].choices[0].delta.thinking_blocks == thinking_blocks
assert not any(
hasattr(c.choices[0].delta, "reasoning_content") for c in chunks[1:]
)
assert not any(
hasattr(c.choices[0].delta, "thinking_blocks") for c in chunks[1:]
)
class TestHandleInvalidParallelToolCalls:
def test_none_input(self):