Skip to content

fix: handle Responses API event shape in OpenAI stream - #586

Open
ShreyaSev wants to merge 1 commit into
AsyncFuncAI:mainfrom
ShreyaSev:fix/openai-responses-stream-shape
Open

fix: handle Responses API event shape in OpenAI stream#586
ShreyaSev wants to merge 1 commit into
AsyncFuncAI:mainfrom
ShreyaSev:fix/openai-responses-stream-shape

Conversation

@ShreyaSev

Copy link
Copy Markdown

Fixes #585

Problem

respond_stream in the OpenAI streamer consumes the stream assuming
Chat Completions chunks, but adalflow returns Responses API events,
which have no choices attribute:

File "/app/api/chat/_stream.py", line 169, in respond_stream chunk.choices AttributeError: 'ResponseCreatedEvent' object has no attribute 'choices'

The stream raises on the first event, before yielding any text, so the
downstream structure parser then fails with a misleading
No valid <wiki_structure> XML found in response.

Fix

Handle both event shapes in the loop, using getattr so neither
attribute access can raise. Unknown event types (response.created,
response.completed) fall through both branches and are ignored.

The Anthropic streamer in the same file is untouched — it already
reads its own provider's event shape correctly.

Testing

Built from this branch and generated a wiki successfully with the
OpenAI provider. Previously failed on every attempt.

The OpenAI streamer assumed Chat Completions chunks (chunk.choices),
but adalflow returns Responses API events, raising AttributeError on
the first iteration.

Fixes AsyncFuncAI#585"

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI streaming fails: 'ResponseCreatedEvent' object has no attribute 'choices'

1 participant