-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Firebase AI] Handle empty or unknown Part
data
#15262
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
Conversation
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.
Code Review
This pull request introduces robust handling for empty or unknown Part
data in GenerateContentResponse
. For streaming calls, responses with only empty candidates are now skipped, improving the developer experience. For unary calls, an error is thrown only if all candidates in a response are empty. This is a solid improvement that also resolves decoding issues with newer models. The changes are well-structured, and the addition of new tests and updates to existing ones ensure the new logic is covered. I have one minor suggestion to use a more specific log code.
Added handling for
GenerateContentResponse
values that contain noparts
. When streaming, these are skipped since the developer can't act upon them. In unary calls, throws only if all candidates are empty since, unlike streaming, no additional responses will be returned by the backend (and therefore an empty response would be an error).This PR resolves decoding issues when using the
gemini-2.5-flash-image-preview
("nano banana") model with the Gemini Developer API to generate images, as well as hardening the decoding against malformed responses that were being returned by Vertex AI (now fixed in the backend).