This commit is contained in:
agustin18 2026-11-06 23:54:42 +00:00 • committed by GitHub
commit 71fd416955
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 0 deletions

View file

@ -1411,6 +1411,15 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
elif handle_raw_dict_callback is not None:
choice, index = handle_raw_dict_callback(item=raw_item, index=index)
if choice is not None:
if pending_reasoning_items:
choice.message = choice.message.model_copy(
update={
"reasoning_items": _as_chat_reasoning_items(pending_reasoning_items),
"reasoning_content": reasoning_content,
}
)
pending_reasoning_items = () # flush
reasoning_content = None
choices.append(choice)
else:
pass # don't fail request if item in list is not supported

View file

@ -4363,6 +4363,34 @@ def test_convert_response_output_merges_raw_dict_message_and_function_call() ->
assert len(choices[0].message.tool_calls) == 1
def test_convert_response_output_keeps_reasoning_before_raw_dict_message() -> None:
handler: Final = LiteLLMResponsesTransformationHandler()
reasoning: Final = ResponseReasoningItem(
id="rs_raw_before",
summary=[Summary(type="summary_text", text="Checking the forecast.")],
type="reasoning",
content=None,
encrypted_content=None,
status=None,
)
raw_message: Final = {
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": "Let me check.", "annotations": []}],
}
choices: Final = LiteLLMResponsesTransformationHandler._convert_response_output_to_choices(
(reasoning, raw_message),
handle_raw_dict_callback=handler._handle_raw_dict_response_item,
)
assert len(choices) == 1
assert choices[0].message.content == "Let me check."
assert choices[0].message.reasoning_content == "Checking the forecast."
assert choices[0].message.reasoning_items is not None
assert [item["id"] for item in choices[0].message.reasoning_items] == ["rs_raw_before"]
def test_convert_tools_to_responses_format_flattens_nested_custom_tool():
from litellm.completion_extras.litellm_responses_transformation.transformation import (
LiteLLMResponsesTransformationHandler,