Skip to content

Commit 35dcc6a

Browse files
authored
Drop assertion that Google streaming chunk has candidates (#2960)
1 parent b36b598 commit 35dcc6a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
578578
async for chunk in self._response:
579579
self._usage = _metadata_as_usage(chunk)
580580

581-
assert chunk.candidates is not None
581+
if not chunk.candidates:
582+
continue # pragma: no cover
583+
582584
candidate = chunk.candidates[0]
583585

584586
if chunk.response_id: # pragma: no branch
@@ -610,7 +612,10 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
610612
else: # pragma: no cover
611613
raise UnexpectedModelBehavior('Content field missing from streaming Gemini response', str(chunk))
612614

613-
parts = candidate.content.parts or []
615+
parts = candidate.content.parts
616+
if not parts:
617+
continue # pragma: no cover
618+
614619
for part in parts:
615620
if part.thought_signature:
616621
signature = base64.b64encode(part.thought_signature).decode('utf-8')

0 commit comments

Comments
 (0)