Feature/add gemini api support#122
Closed
cuipengfei wants to merge 15 commits into
Closed
Conversation
…forcing model requirement
…API; enhance translation handling for nested function responses
- Implement Gemini API endpoints (generateContent, streamGenerateContent, countTokens) - Add request/response translation between Gemini and OpenAI formats - Support function calling with proper tool_call_id mapping - Handle streaming responses with chunk-by-chunk translation - Add debug logging system for troubleshooting - Implement tool call utilities for parameter accumulation - Add comprehensive test coverage for all Gemini features This implementation provides full compatibility with Google's Gemini API specification while using GitHub Copilot as the underlying LLM provider.
- Remove CLAUDE.md (local development guide) - Remove gemini-plan.md (implementation planning doc) - Simplify .gitignore to only add .env (generic ignore)
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds Gemini API compatibility layer: routing, request/response translation, streaming adaptation, tool call handling, and extensive test coverage. Key changes introduce new generate-content route, translation utilities, tool-call accumulation logic, and debug logging.
- Adds geminiRouter and handlers for generateContent, streamGenerateContent, and countTokens endpoints.
- Implements translation between Gemini request/response formats and existing OpenAI/Copilot internal structures, including streaming tool call argument accumulation.
- Introduces comprehensive test suites covering routing, validation, translation edge cases, streaming behavior, and tool call workflows.
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/server.ts | Registers Gemini router to expose new v1beta endpoints. |
| src/routes/generate-content/route.ts | Adds URL pattern routing for generate, stream, and countTokens operations. |
| src/routes/generate-content/handler.ts | Core handlers for non-stream, stream, and token count flows plus fallback streaming conversion. |
| src/routes/generate-content/translation.ts | Large translation layer Gemini <-> OpenAI, tool call/message normalization, streaming chunk translation. |
| src/routes/generate-content/utils.ts | Finish reason mapping utility. |
| src/routes/generate-content/types.ts | Defines Gemini request/response and streaming types. |
| src/lib/tool-call-utils.ts | Tool declaration translation and streaming tool call argument accumulator. |
| src/lib/debug-logger.ts | Debug logging utilities for requests/responses. |
| tests/generate-content/*.test.ts | Extensive new test coverage for routing, validation, translation, streaming, and edge cases. |
| tests/generate-content/_test-utils.ts | Shared test helper utilities. |
| tests/generate-content/test-types.ts | Test-only type helpers. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…message processing
…nd enhance streaming response handling
Contributor
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 18 out of 20 changed files in this pull request and generated 8 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Removed outdated translation coverage tests and replaced them with new multi-turn and tool call tests. - Introduced structured test cases for multi-turn interactions, ensuring proper handling of tool calls and deduplication. - Improved tool call processing tests, including cleanup of incomplete calls and handling of inline data. - Streamlined translation test cases to utilize shared utility functions for consistency and clarity. - Added validation for tool call ID length constraints and ensured proper mapping of tool configurations. - Enhanced error handling tests to cover various failure scenarios and ensure graceful degradation.
…e obsolete tests, and enhance error handling coverage
- Implemented tests for complex interleaved multi-tool streaming in `streaming-multi-tool-interleaved.test.ts`, verifying correct outputs for multiple tools. - Added tests for scenarios where name and arguments are received in the same chunk in `streaming-name-and-args-same-chunk.test.ts`, ensuring no duplicate outputs. - Created tests for name-only followed by args-only chunks in `streaming-name-then-args-single-output.test.ts`, confirming single complete outputs and preventing duplicates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.