From 22558f6cdc47a06501a485ec12103c835dc03c81 Mon Sep 17 00:00:00 2001 From: Viktor Malyi Date: Wed, 23 Jul 2025 11:14:36 +0200 Subject: [PATCH] Fix ResponseTextDeltaEvent validation error for non-OpenAI model providers The `ChatCmplStreamHandler.handle_stream()` method fails with a Pydantic validation error when creating `ResponseTextDeltaEvent` objects during streaming operations with non-OpenAI model providers (e.g., Gemini via Google's OpenAI-compatible API). Streaming should work seamlessly with all OpenAI-compatible model providers, including those that don't provide logprobs data (like Gemini). The `ResponseTextDeltaEvent` should be created with proper logprobs handling that: 1. Uses actual logprobs data when available (OpenAI models) 2. Falls back to empty list when not available (non-OpenAI providers) 3. Maintains backward compatibility --- src/agents/models/chatcmpl_stream_handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/agents/models/chatcmpl_stream_handler.py b/src/agents/models/chatcmpl_stream_handler.py index eab4c291b..3fc77af7c 100644 --- a/src/agents/models/chatcmpl_stream_handler.py +++ b/src/agents/models/chatcmpl_stream_handler.py @@ -194,6 +194,7 @@ async def handle_stream( content_index=state.text_content_index_and_output[0], delta=delta.content, item_id=FAKE_RESPONSES_ID, + logprobs=getattr(delta, "logprobs", []) or [], # logprobs are not always delivered by non-OpenAI model providers output_index=state.reasoning_content_index_and_output is not None, # fixed 0 -> 0 or 1 type="response.output_text.delta",