From 7ae3ae611025fc8f211c5eac18598494b69200c7 Mon Sep 17 00:00:00 2001 From: Shreya Sevelar <116109558+ShreyaSev@users.noreply.github.com> Date: Tue, 8 Sep 2026 22:29:35 +0530 Subject: [PATCH] Update _stream.pyfix: handle Responses API event shape in OpenAI stream The OpenAI streamer assumed Chat Completions chunks (chunk.choices), but adalflow returns Responses API events, raising AttributeError on the first iteration. Fixes #585" --- api/chat/_stream.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/chat/_stream.py b/api/chat/_stream.py index dcb7f52ab..921e8b2c2 100644 --- a/api/chat/_stream.py +++ b/api/chat/_stream.py @@ -165,13 +165,21 @@ async def respond_stream(self, prompt: str) -> AsyncIterator[str]: ) async for chunk in response: + # Responses API event shape + if getattr(chunk, "type", "") == "response.output_text.delta": + delta = getattr(chunk, "delta", None) + if delta: + yield delta + continue + + # Chat Completions chunk shape + choices = getattr(chunk, "choices", None) if ( - chunk.choices - and chunk.choices[0].delta is not None - and chunk.choices[0].delta.content is not None + choices + and choices[0].delta is not None + and choices[0].delta.content is not None ): - yield chunk.choices[0].delta.content - + yield choices[0].delta.content class OpenAIChatStreamer(_OpenAICompatStreamer): provider = "openai"