mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(responses): attach accumulated reasoning items to raw-dict callback choices
This commit is contained in:
parent
353896a664
commit
3efd070c95
2 changed files with 29 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue