Skip to content

fix(go/plugins/googlegenai): handle multi-field response parts#5198

Draft
apascal07 wants to merge 1 commit intomainfrom
claude/objective-agnesi-7b4417
Draft

fix(go/plugins/googlegenai): handle multi-field response parts#5198
apascal07 wants to merge 1 commit intomainfrom
claude/objective-agnesi-7b4417

Conversation

@apascal07
Copy link
Copy Markdown
Collaborator

Summary

  • Nano Banana 2 (vertexai/gemini-3.1-flash-image-preview) returns response parts that populate both Text (a caption) and InlineData (the image bytes) in a single genai.Part. The current code in translateCandidate asserts at most one populated field per part and panics with expected only 1 content part in response, got 2, part: ....
  • Replace the panic with logic that emits one ai.Part per populated field. The ThoughtSignature, when present, is attached to the first emitted part so a single signature still round-trips back to the API rather than being duplicated.
  • Add a regression test TestTranslateCandidateMultiFieldPart covering the text + inline-data case and signature placement.

resp.Media() from the issue's reproducer iterates all parts and returns the first IsMedia(), 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/...
  • Manually verify against vertexai/gemini-3.1-flash-image-preview using the reproducer from the issue

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
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] Panic when using Nano Banana 2 for image generation

1 participant