Skip to content

feat(llm): add built-in Google Gemini provider preset#3

Open
chethanuk wants to merge 5 commits into
mainfrom
fix/issue-49-gemini-provider
Open

feat(llm): add built-in Google Gemini provider preset#3
chethanuk wants to merge 5 commits into
mainfrom
fix/issue-49-gemini-provider

Conversation

@chethanuk

@chethanuk chethanuk commented Jul 8, 2026

Copy link
Copy Markdown
Owner

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 existing OpenAIClient path, mirroring the other 14 non-Anthropic presets.

Includes one piece of real logic: a new Provider.LegacyMaxTokens flag. Gemini's OpenAI-compat endpoint expects the legacy max_tokens field rather than max_completion_tokens (the SDK's default). The flag is threaded Provider → ResolvedEndpoint → ClientConfig → buildOpenAIParams so a provider: gemini user always sends max_tokens; every other preset is unchanged (defaults false).

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) and gemini-2.5-pro.

Known limitation (deliberately out of scope): Gemini 3.x models are not shipped. Live testing showed every 3.x preview (gemini-3.1-pro-preview, gemini-3-flash-preview, gemini-3.1-flash-lite) returns HTTP 400 on OCR's multi-turn reviews: 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-compat client does not yet do. They pass a plain llm test but break real reviews, so shipping them would be a footgun. Re-enabling 3.x would require thought_signature handling in the OpenAI-compat client — a separate change.

Note: a user who hand-configures Gemini via OCR_LLM_URL / the legacy llm block (instead of the gemini preset) still sends max_completion_tokens; the preset is the supported path. Gemini currently tolerates max_completion_tokens (no error), but the preset emits the documented max_tokens so the token budget is reliably honored.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally (make check: go mod tidy + go fmt + go vet + build + full test suite → check passed; 188 tests in internal/llm).
  • Manual testing (described below)

Manual / live smoke testing against the real Gemini API:

  1. Preset pathocr config set provider gemini (+ GEMINI_API_KEY env-var fallback) → ocr llm test connects and ocr review --commit <hash> completes a real review. A pass-through logging proxy confirmed the request body carries max_tokens (not max_completion_tokens) on the wire, including on the tools=true review request.
  2. Raw/direct pathOCR_LLM_URL=… OCR_USE_ANTHROPIC=false ocr llm test (bypasses the preset) sends max_completion_tokens, confirming the flag is what flips the field.
  3. Model verification — all 5 candidate models were exercised on the tool-calling review path; only the two GA 2.5 models completed reviews cleanly, which is why the 3.x previews are excluded (see Known limitation above).

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (en/zh/ja provider tables)
  • I have signed the CLA

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

  • Added a built-in gemini provider that uses Google’s OpenAI-compatible endpoint and GEMINI_API_KEY
  • Gemini now sends max_tokens instead of max_completion_tokens, which prevents review failures on that provider
  • Limited the Gemini preset to the verified working models: gemini-2.5-flash and gemini-2.5-pro
  • Documented the new provider in the configuration guides

Impact

✅ 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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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.

chethanuk added 5 commits July 8, 2026 19:54
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

codeant-ai Bot commented Jul 8, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai

codeant-ai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chethanuk has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@chethanuk, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9ed16cfb-3b02-442e-b062-5ed743e2b4b3

📥 Commits

Reviewing files that changed from the base of the PR and between e2d75b7 and 1bfbd83.

📒 Files selected for processing (9)
  • internal/llm/client.go
  • internal/llm/client_test.go
  • internal/llm/providers.go
  • internal/llm/providers_test.go
  • internal/llm/resolver.go
  • internal/llm/resolver_test.go
  • pages/src/content/docs/en/configuration.md
  • pages/src/content/docs/ja/configuration.md
  • pages/src/content/docs/zh/configuration.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-49-gemini-provider

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jul 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 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.

Comment thread internal/llm/resolver.go

var url, protocol, authHeader, model string
var extraBody map[string]any
var legacyMaxTokens bool

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

codeant-ai Bot commented Jul 8, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Gemini API

1 participant