feat(llm): add built-in Google Gemini provider preset#3
Conversation
Adds a preset for Google's Gemini API via its OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai), routed through the existing OpenAIClient path. Model list reflects the current Gemini 3.x lineup. Introduces the LegacyMaxTokens Provider field (wired into request building in a follow-up commit). Closes alibaba#49
… preset Gemini's OpenAI-compatible endpoint mishandles the newer max_completion_tokens field. Thread the Provider.LegacyMaxTokens preset flag through ResolvedEndpoint and ClientConfig so buildOpenAIParams emits the legacy max_tokens field when the preset requires it. No behavior change for existing presets (LegacyMaxTokens defaults false).
Documents the new gemini preset (openai protocol, GEMINI_API_KEY) in the en/zh/ja configuration provider tables.
Live smoke testing revealed all Gemini 3.x preview models (gemini-3.1-pro-preview, gemini-3-flash-preview, gemini-3.1-flash-lite) return HTTP 400 on OCR's multi-turn tool-calling review path: Gemini 3.x tool-call responses carry a google.thought_signature in extra_content that must be echoed back on the next turn, which the OpenAI-compatible client does not yet do. They pass a plain llm test but break real reviews. Ship only the GA Gemini 2.5 models (gemini-2.5-flash, gemini-2.5-pro), both verified end-to-end on the tool-calling review path. Re-enabling 3.x would require thought_signature handling in the OpenAI-compat client.
A cross-model review noted the preset -> ResolvedEndpoint -> ClientConfig wiring for LegacyMaxTokens was unguarded: a dropped assignment would keep tests green while a provider:gemini user silently sends max_completion_tokens. Adds a resolver test asserting the gemini preset resolves with LegacyMaxTokens=true (and non-preset stays false), and a MaxTokens==0 case that both token fields stay unset.
|
CodeAnt AI is reviewing your PR. |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
There was a problem hiding this comment.
chethanuk has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request adds support for the Google Gemini API as an OpenAI-compatible provider. It introduces a LegacyMaxTokens configuration flag to allow endpoints like Gemini to use the legacy max_tokens parameter instead of max_completion_tokens. This flag is propagated from the provider presets to the OpenAI client, with corresponding unit tests and documentation updates. The feedback suggests extending this LegacyMaxTokens option to custom providers in the future, as they may also connect to endpoints requiring the legacy parameter.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| var url, protocol, authHeader, model string | ||
| var extraBody map[string]any | ||
| var legacyMaxTokens bool |
There was a problem hiding this comment.
Currently, LegacyMaxTokens is only set when resolving a preset provider (where isPreset is true). However, custom providers configured via custom_providers or the legacy llm block might also connect to OpenAI-compatible endpoints that require the legacy max_tokens parameter instead of max_completion_tokens. Consider adding a LegacyMaxTokens field (perhaps as a *bool to distinguish unset from false) to providerEntryConfig and llmFileConfig in a future update so that custom providers can also opt into using legacy max tokens if needed.
|
CodeAnt AI finished reviewing your PR. |
User description
Description
Adds a built-in provider preset for Google Gemini via its OpenAI-compatible endpoint (
https://generativelanguage.googleapis.com/v1beta/openai), so OpenCodeReview can run reviews against Gemini models with no new client, SDK, or protocol — it routes through the existingOpenAIClientpath, mirroring the other 14 non-Anthropic presets.Includes one piece of real logic: a new
Provider.LegacyMaxTokensflag. Gemini's OpenAI-compat endpoint expects the legacymax_tokensfield rather thanmax_completion_tokens(the SDK's default). The flag is threadedProvider → ResolvedEndpoint → ClientConfig → buildOpenAIParamsso aprovider: geminiuser always sendsmax_tokens; every other preset is unchanged (defaultsfalse).Model list: ships the two GA models that are verified working end-to-end on OCR's tool-calling review path —
gemini-2.5-flash(default) andgemini-2.5-pro.Type of Change
How Has This Been Tested?
make testpasses locally (make check:go mod tidy+go fmt+go vet+ build + full test suite →check passed; 188 tests ininternal/llm).Manual / live smoke testing against the real Gemini API:
ocr config set provider gemini(+GEMINI_API_KEYenv-var fallback) →ocr llm testconnects andocr review --commit <hash>completes a real review. A pass-through logging proxy confirmed the request body carriesmax_tokens(notmax_completion_tokens) on the wire, including on thetools=truereview request.OCR_LLM_URL=… OCR_USE_ANTHROPIC=false ocr llm test(bypasses the preset) sendsmax_completion_tokens, confirming the flag is what flips the field.Checklist
go fmt,go vet)Related Issues
Closes alibaba#49
CodeAnt-AI Description
Add Gemini as a built-in provider and make its reviews work with the right token field
What Changed
geminiprovider that uses Google’s OpenAI-compatible endpoint andGEMINI_API_KEYmax_tokensinstead ofmax_completion_tokens, which prevents review failures on that providergemini-2.5-flashandgemini-2.5-proImpact
✅ Gemini reviews run without token-field errors✅ Fewer failed tool-calling reviews on Gemini✅ Easier Gemini setup with a built-in preset💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.