-
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 4 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,14 @@ def _process_response(self, response: GenerateContentResponse) -> ModelResponse: | |
| raise UnexpectedModelBehavior( | ||
| f'Content filter {raw_finish_reason.value!r} triggered', response.model_dump_json() | ||
| ) | ||
| elif raw_finish_reason and raw_finish_reason.value == 'MALFORMED_FUNCTION_CALL': | ||
| parts = [] | ||
| else: | ||
| raise UnexpectedModelBehavior( | ||
| 'Content field missing from Gemini response', response.model_dump_json() | ||
| ) # pragma: no cover | ||
| parts = candidate.content.parts or [] | ||
| else: | ||
| parts = candidate.content.parts or [] | ||
|
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. If
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. Ah, you're totally right, I wasn't reading right |
||
|
|
||
| usage = _metadata_as_usage(response) | ||
| return _process_response_from_parts( | ||
|
|
@@ -652,6 +655,8 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]: | |
| if self.finish_reason == 'stop': # pragma: no cover | ||
| # Normal completion - skip this chunk | ||
| continue | ||
| elif raw_finish_reason and raw_finish_reason.value == 'MALFORMED_FUNCTION_CALL': | ||
| continue | ||
| elif 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() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.