fix(test/audio): skip empty-choices chunks in streaming response check

OpenAI streaming with include_usage=True emits a final usage chunk
with choices=[]. check_streaming_response() assumed every chunk has
at least one choice and crashed with IndexError on chunk.choices[0].

Add an early-continue guard to skip usage-only chunks.
This commit is contained in:
Ishaan Jaffer 2026-04-13 16:59:32 -07:00
parent 9640dd5765
commit 63eb58a82b
No known key found for this signature in database

View file

@ -34,6 +34,8 @@ async def check_streaming_response(completion):
_audio_id = None
async for chunk in completion:
print(chunk)
if not chunk.choices: # skip usage-only chunks (choices=[])
continue
_choice: StreamingChoices = chunk.choices[0]
if _choice.delta.audio is not None:
if _choice.delta.audio.get("data") is not None:
@ -84,7 +86,7 @@ async def test_audio_output_from_model(stream):
@pytest.mark.asyncio
@pytest.mark.parametrize("stream", [True, False])
@pytest.mark.parametrize("model", ["gpt-4o-audio-preview"]) # "gpt-4o-audio-preview",
@pytest.mark.parametrize("model", ["gpt-4o-audio-preview"]) # "gpt-4o-audio-preview",
async def test_audio_input_to_model(stream, model):
# Fetch the audio file and convert it to a base64 encoded string
audio_format = "pcm16"