Skip to content

Conversation

@Darley-Wey
Copy link
Contributor

Summary

Fixes #1293
When Claude API sends an assistant message with empty text content, the Antigravity translator was creating an empty part object {} with no data field, causing Gemini API to return error:

required oneof field 'data' must have one initialized field

Changes

  1. Skip empty text parts - When text field is empty string, skip adding the part to avoid creating invalid empty objects
  2. Skip messages with empty parts - After processing all content, if the parts array is empty, skip adding the entire message

Files Changed

  • internal/translator/antigravity/claude/antigravity_claude_request.go

Testing

All existing tests pass:

go test ./internal/translator/antigravity/claude/... -v

Example

Before fix, this request would fail:

{
  "messages": [
    {"role": "user", "content": [{"type": "text", "text": "你好"}]},
    {"role": "assistant", "content": [{"type": "text", "text": ""}]},
    {"role": "user", "content": [{"type": "text", "text": "Suggest a title"}]}
  ]
}

After fix, the empty assistant message is filtered out and the request succeeds.

When Claude API sends an assistant message with empty text content like:
{"role":"assistant","content":[{"type":"text","text":""}]}
The translator was creating a part object {} with no data field,
causing Gemini API to return error:
"required oneof field 'data' must have one initialized field"
This fix:
1. Skips empty text parts (text="") during translation
2. Skips entire messages when their parts array becomes empty
This ensures compatibility when clients send empty assistant messages
in their conversation history.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Darley-Wey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where empty assistant messages from the Claude API, when translated by the Antigravity translator, would lead to invalid requests for the Gemini API. The changes ensure that both empty text parts and messages containing only empty parts are filtered out during the translation process, preventing a "required oneof field 'data' must have one initialized field" error from the Gemini API.

Highlights

  • Empty Text Part Handling: Modified the ConvertClaudeRequestToAntigravity function to skip adding text parts to the client content if their prompt (text content) is an empty string, preventing the creation of invalid empty part objects that would cause Gemini API errors.
  • Empty Message Handling: Implemented a check to skip entire messages if, after processing all their content, the resulting parts array is empty or invalid, thus avoiding Gemini API errors for messages without any valid parts.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

The pull request effectively addresses the issue of empty text parts and messages causing errors with the Gemini API. The changes correctly implement checks to skip these invalid parts and messages, ensuring the generated requests are well-formed. The code is clear, and the comments provide good context for the introduced logic. This is a solid fix for the reported problem.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant