Skip to content
Merged
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
7 changes: 5 additions & 2 deletions app/openai_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ def consume_openai_stream_to_write_reply(
spent_seconds = time.time() - start_time
if timeout_seconds < spent_seconds:
raise TimeoutError()
# Some versions of the Azure OpenAI API return an empty choices array in the first chunk
if context.get("OPENAI_API_TYPE") == "azure" and not chunk.choices:
# Streaming may emit control/usage/keep-alive chunks without choices,
# so guard before indexing
if not chunk.choices:
logging.debug("Stream chunk missing choices; skipping")
continue

item = chunk.choices[0].model_dump()
if item.get("finish_reason") is not None:
finish_reason = item.get("finish_reason")
Expand Down