fix(streaming): guard raise_on_model_repetition against empty choices chunks

Vertex Gemini Flash/Flash Lite with web_search_options emits metadata-only
chunks that have choices=[]. These are appended to self.chunks normally, but
raise_on_model_repetition unconditionally accesses choices[0] on the last two
chunks, raising IndexError on any such metadata chunk.

Add an early return when either of the two compared chunks has no choices.
The repetition check is meaningless for content-less chunks anyway.
This commit is contained in:
Rishab Motgi 2026-05-18 14:09:43 -07:00
parent 8c6625216b
commit edf4b885ba

View file

@ -269,6 +269,9 @@ class CustomStreamWrapper:
if len(self.chunks) < 2:
return
if not self.chunks[-1].choices or not self.chunks[-2].choices:
return
last_content = self.chunks[-1].choices[0].delta.content
if (