-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Retry instead of error when Google response is empty with MALFORMED_FUNCTION_CALL or other recoverable finish reason
#3300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6166f3d
86b3cf3
2997f66
4288e9e
a68b631
25e971d
bd61d88
2c14f87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,11 +471,9 @@ def _process_response(self, response: GenerateContentResponse) -> ModelResponse: | |
| raise UnexpectedModelBehavior( | ||
| f'Content filter {raw_finish_reason.value!r} triggered', response.model_dump_json() | ||
| ) | ||
| else: | ||
| raise UnexpectedModelBehavior( | ||
| 'Content field missing from Gemini response', response.model_dump_json() | ||
| ) # pragma: no cover | ||
| parts = candidate.content.parts or [] | ||
| parts = [] | ||
| else: | ||
| parts = candidate.content.parts or [] | ||
|
|
||
| usage = _metadata_as_usage(response) | ||
| return _process_response_from_parts( | ||
|
|
@@ -649,17 +647,12 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]: | |
| # ) | ||
|
|
||
| if candidate.content is None or candidate.content.parts is None: | ||
| if self.finish_reason == 'stop': # pragma: no cover | ||
| # Normal completion - skip this chunk | ||
| continue | ||
| elif self.finish_reason == 'content_filter' and raw_finish_reason: # pragma: no cover | ||
| if self.finish_reason == 'content_filter' and raw_finish_reason: # pragma: no cover | ||
| raise UnexpectedModelBehavior( | ||
| f'Content filter {raw_finish_reason.value!r} triggered', chunk.model_dump_json() | ||
| ) | ||
| else: # pragma: no cover | ||
| raise UnexpectedModelBehavior( | ||
| 'Content field missing from streaming Gemini response', chunk.model_dump_json() | ||
| ) | ||
| continue | ||
|
|
||
| parts = candidate.content.parts | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that we could get here if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that call continue and thus let us proceed with the next chunk? I am not sure I can follow you right now.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're quite right, I think I had been at my desk for too long when I reviewed this :) |
||
| if not parts: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we could get here if
candidate.content is NoneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
candidate.content is None, parts would be [] and we would continue with that, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're totally right, I wasn't reading right