mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(responses): handle incomplete response with reasoning-only output
When a Responses API response has status "incomplete" and all output tokens were consumed by reasoning (no text output), the transformation raised ValueError because no choices were created. Now creates a choice with the reasoning content and empty text, with finish_reason="length".
This commit is contained in:
parent
26fcbc93e5
commit
4aee9fb560
1 changed files with 20 additions and 0 deletions
|
|
@ -581,6 +581,26 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
|
|||
reasoning_content = None
|
||||
pending_reasoning_item = None
|
||||
|
||||
# If no choices were created but we have pending reasoning content
|
||||
# (e.g. incomplete response where all tokens went to reasoning),
|
||||
# create a choice with empty text so the reasoning is not lost.
|
||||
if len(choices) == 0 and (
|
||||
reasoning_content is not None or pending_reasoning_item is not None
|
||||
):
|
||||
msg = Message(
|
||||
content="",
|
||||
reasoning_content=reasoning_content,
|
||||
reasoning_items=cast(
|
||||
Optional[List[ChatCompletionReasoningItem]],
|
||||
[pending_reasoning_item]
|
||||
if pending_reasoning_item is not None
|
||||
else None,
|
||||
),
|
||||
)
|
||||
choices.append(
|
||||
Choices(message=msg, finish_reason="length", index=index)
|
||||
)
|
||||
|
||||
return choices
|
||||
|
||||
def transform_response( # noqa: PLR0915
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue