We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9454c9e commit 0abdb57Copy full SHA for 0abdb57
app/openai_ops.py
@@ -319,9 +319,12 @@ def consume_openai_stream_to_write_reply(
319
spent_seconds = time.time() - start_time
320
if timeout_seconds < spent_seconds:
321
raise TimeoutError()
322
- # Some versions of the Azure OpenAI API return an empty choices array in the first chunk
323
- 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
324
+ if not chunk.choices:
325
+ logging.debug("Stream chunk missing choices; skipping")
326
continue
327
+
328
item = chunk.choices[0].model_dump()
329
if item.get("finish_reason") is not None:
330
finish_reason = item.get("finish_reason")
0 commit comments