Skip to content

Comments

feat(google): add native Google Gemini API integration#2346

Merged
amitksingh1490 merged 9 commits intomainfrom
gemini-compatible
Feb 2, 2026
Merged

feat(google): add native Google Gemini API integration#2346
amitksingh1490 merged 9 commits intomainfrom
gemini-compatible

Conversation

@amitksingh1490
Copy link
Contributor

@amitksingh1490 amitksingh1490 commented Jan 31, 2026

Summary

Implement native support for the Google Gemini API (Vertex AI) to enable advanced features like tool use, reasoning, and robust streaming.

Context

Previously, Google providers were handled via a generic OpenAI-compatible layer. This limited access to Gemini-specific features such as "thinking" blocks (Gemini 2.0), native tool calling structures, and proper error handling for safety filters. This PR introduces a dedicated implementation to unlock the full capabilities of the Gemini models.

Changes

  • Native Provider Implementation: Added GoogleResponseRepository and DTOs in forge_app::dto::google to handle the specific JSON structure of the Gemini API.
  • Advanced Model Features: Support for thinking_config (reasoning models), safety settings, and grounding metadata.
  • Tool Calling Support: Implemented FunctionCall and FunctionResponse handling, including logic to group consecutive tool results to satisfy API requirements.
  • Streaming Support: Robust SSE handling for streamGenerateContent endpoints.
  • Configuration: Updated provider.json to use the new Google response type for Vertex AI models.

Key Implementation Details

  • Implemented TryFrom conversions between internal domain types (Context, ChatCompletionMessage) and Google's API types (Request, Response).
  • Added robustness for handling blocked responses (safety filters) by making candidates optional and checking promptFeedback.
  • Integrated into the main ForgeChatRepository routing logic.

Use Cases

  • Reasoning Models: Use Gemini 2.0 Flash Thinking with proper thought block parsing.
  • Tool Use: Seamlessly use tools with Gemini models, handling the specific message ordering requirements (grouping consecutive tool outputs).
  • Safety Handling: Gracefully handle and report safety blocks instead of JSON parsing errors.

Testing

  1. Configure a Google Vertex AI provider in provider.json or via environment variables.
  2. Run a chat session with a Gemini model (e.g., gemini-2.0-flash).
  3. Verify streaming responses work correctly.
  4. Test tool usage (e.g., file reading) and ensure consecutive tool calls are handled without API errors.
  5. Verify that safety blocks are reported as errors rather than crashing the application.

Links

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Jan 31, 2026
@amitksingh1490 amitksingh1490 changed the title feat(google): add native gemini api implementation feat(google): add native Google Gemini API integration Jan 31, 2026
autofix-ci bot and others added 8 commits January 31, 2026 07:35
@amitksingh1490 amitksingh1490 merged commit 9c788e1 into main Feb 2, 2026
11 checks passed
@amitksingh1490 amitksingh1490 deleted the gemini-compatible branch February 2, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant