Repository navigation
Conversation
Summary of ChangesHello, 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 introduces significant enhancements to the Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for OpenAI-compatible providers by adding a new OpenAIContentGenerator. The changes are extensive, including the new generator, modifications to the content generator factory, and updates to token limit calculations. The implementation is thorough and includes comprehensive tests.
My review identified a potential issue in the new OpenAIContentGenerator. There's a risk of silently dropping tool responses when multiple responses lack an ID due to how they are deduplicated. This issue is flagged as high severity and should be addressed to ensure correctness and robustness.
| for (const fr of funcResponses) { | ||
|
|
||
| const frId = fr.functionResponse!.id ?? ''; | ||
| seenToolIds.set(frId, fr); | ||
| } |
There was a problem hiding this comment.
There's a potential for data loss here when handling functionResponse parts. If multiple functionResponse parts in the contents array are missing an id, they will all be assigned an empty string '' as their frId. Consequently, they will overwrite each other in the seenToolIds map, and only the last one will be processed. This could lead to silently dropping tool responses, causing incorrect behavior in the agent loop.
There was a problem hiding this comment.
Fixed in 38cebcd — functionResponse parts without an id now get unique index-based fallback keys (_fr_0, _fr_1, ...) instead of collapsing into empty string. No data loss.
Enable gemini-cli to work with any OpenAI-compatible API endpoint, including OpenAI, Anthropic Claude (via proxy), local models (Ollama, vLLM), and corporate LLM gateways. Architecture: - OpenAIContentGenerator implements the ContentGenerator interface, translating Gemini's Content/Part format to OpenAI chat completions and back - Factory in contentGenerator.ts detects OPENAI_COMPATIBLE_ENDPOINT + OPENAI_COMPATIBLE_API_KEY env vars and creates the right generator - Full streaming support via SSE parsing with tool call accumulation - Model-aware max_tokens defaults prevent silent output truncation - Pre-send context budget enforcement trims tool outputs to fit smaller context windows (Claude 200K, GPT 128K) - Token limits expanded with pattern-based matching for non-Gemini models All Gemini-native functionality is preserved unchanged. OpenAI support is purely additive. Made-with: Cursor
Avoid data loss when multiple functionResponse parts lack an id field. Previously they all mapped to empty string and only the last survived. Now each gets a unique fallback key (_fr_0, _fr_1, ...). Made-with: Cursor
38cebcd to
3256dd6
Compare
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383). We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'. This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community! |
Fixes #23385
What
Add
OpenAIContentGeneratorthat implements the existingContentGeneratorinterface, enabling gemini-cli to work with any OpenAI-compatible API endpoint — OpenAI, Anthropic Claude (via proxy), local models (Ollama, vLLM), and corporate LLM gateways.Why
Multi-provider support is the most impactful way to grow gemini-cli's community. The agent loop, MCP integration, tool system, and TUI are excellent — but they're currently locked to the Gemini API. This PR unlocks them for every OpenAI-compatible model while preserving all Gemini-native functionality unchanged.
This is battle-tested: we've been running this architecture against Claude Opus 4, GPT-4o, and corporate LLM proxies on large codebases (100K+ files) for weeks.
How
packages/core/src/core/openaiContentGenerator.tspackages/core/src/core/contentGenerator.tsOPENAI_COMPATIBLEauth type, env var detection, factory wiringpackages/core/src/core/tokenLimits.tspackages/cli/src/ui/utils/updateCheck.tspackages/core/src/core/openaiContentGenerator.test.tspackages/core/src/core/tokenLimits.test.tsActivation (zero-config for existing users):
Test Plan
npx vitest run packages/core/src/core/openaiContentGenerator.test.ts— 11 tests passnpx vitest run packages/core/src/core/tokenLimits.test.ts— 6 tests pass (including 7 new model cases)npx tsc --noEmit -p packages/core/tsconfig.json— cleanMade with Cursor