fix(go/plugins/googlegenai): handle multi-field response parts#5198
Draft
fix(go/plugins/googlegenai): handle multi-field response parts#5198
Conversation
Nano Banana 2 (gemini-3.1-flash-image-preview) returns response parts with both Text and InlineData populated together, which tripped the "expected only 1 content part in response" panic in translateCandidate. Split each genai.Part with multiple populated fields into separate ai.Parts and attach the ThoughtSignature to the first emitted part so a single signature still round-trips back to the API. Fixes #5195
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the translateCandidate function in the Google GenAI plugin to support genai.Part objects with multiple populated fields, such as text combined with inline data. Previously, the code would panic if more than one field was populated; it now correctly emits a separate ai.Part for each field and ensures that any ThoughtSignature is attached to the first emitted part. A regression test has been added to verify this behavior. I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vertexai/gemini-3.1-flash-image-preview) returns response parts that populate bothText(a caption) andInlineData(the image bytes) in a singlegenai.Part. The current code intranslateCandidateasserts at most one populated field per part and panics withexpected only 1 content part in response, got 2, part: ....ai.Partper populated field. TheThoughtSignature, when present, is attached to the first emitted part so a single signature still round-trips back to the API rather than being duplicated.TestTranslateCandidateMultiFieldPartcovering the text + inline-data case and signature placement.resp.Media()from the issue's reproducer iterates all parts and returns the firstIsMedia(), so the image is recovered correctly even when a text part precedes it.Fixes #5195
Test plan
go test ./plugins/googlegenai/...(existing + new tests pass)go vet ./plugins/googlegenai/...vertexai/gemini-3.1-flash-image-previewusing the reproducer from the issue