mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(responses): check terminal event type for streaming guardrail end-of-stream detection
_check_streaming_has_ended assumed responses_so_far held ModelResponse objects with .choices, but for the Responses API the accumulated chunks are raw SSE event dicts, causing an AttributeError on every call
This commit is contained in:
parent
576e41797e
commit
1667cd8285
1 changed files with 9 additions and 1 deletions
|
|
@ -45,6 +45,7 @@ from litellm.types.llms.openai import (
|
|||
AllMessageValues,
|
||||
ChatCompletionToolCallChunk,
|
||||
ChatCompletionToolParam,
|
||||
ResponsesAPIStreamEvents,
|
||||
)
|
||||
from litellm.types.responses.main import (
|
||||
GenericResponseOutputItem,
|
||||
|
|
@ -586,7 +587,14 @@ class OpenAIResponsesHandler(BaseTranslation):
|
|||
"""
|
||||
Check if the streaming has ended.
|
||||
"""
|
||||
return all(response.choices[0].finish_reason is not None for response in responses_so_far)
|
||||
if not responses_so_far:
|
||||
return False
|
||||
terminal_types = {
|
||||
ResponsesAPIStreamEvents.RESPONSE_COMPLETED.value,
|
||||
ResponsesAPIStreamEvents.RESPONSE_FAILED.value,
|
||||
ResponsesAPIStreamEvents.RESPONSE_INCOMPLETE.value,
|
||||
}
|
||||
return responses_so_far[-1].get("type") in terminal_types
|
||||
|
||||
def get_streaming_string_so_far(self, responses_so_far: List[Any]) -> str:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue