Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions api/chat/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down