fix(responses): attach accumulated reasoning items to raw-dict callback choices

This commit is contained in:
agustin18 2026-09-29 03:08:42 +00:00
parent 353896a664
commit 3efd070c95
2 changed files with 29 additions and 1 deletions

View file

@ -780,6 +780,12 @@ 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.reasoning_items = _as_chat_reasoning_items(pending_reasoning_items)
if reasoning_content:
choice.message.reasoning_content = reasoning_content
pending_reasoning_items.clear()
reasoning_content = None
choices.append(choice)
else:
pass # don't fail request if item in list is not supported

View file

@ -4405,6 +4405,25 @@ def test_map_optional_params_verbosity_merges_into_text():
"message",
id="multiple_reasoning_items_before_output_message",
),
pytest.param(
[
{
"type": "reasoning",
"id": "rs_raw_1",
"summary": [{"type": "summary_text", "text": "Raw Step 1"}],
"encrypted_content": "enc_raw",
},
{
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": "Raw response text"}],
},
],
["rs_raw_1"],
"Raw Step 1",
"raw_dict_message",
id="reasoning_items_before_raw_dict_message",
),
pytest.param(
[
{
@ -4446,7 +4465,10 @@ def test_convert_response_output_to_choices_preserves_all_reasoning_items(
)
handler: Final = LiteLLMResponsesTransformationHandler()
choices: Final = handler._convert_response_output_to_choices(items_to_pass)
choices: Final = handler._convert_response_output_to_choices(
items_to_pass,
handle_raw_dict_callback=handler._handle_raw_dict_response_item,
)
assert len(choices) == 1
msg = choices[0].message