feat: support gemini and openai embeddings passthrough#931
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 significantly expands the proxy's capabilities by introducing explicit support for embedding endpoints from both Gemini and OpenAI. It refines how these specific API paths are recognized and processed, ensuring they are handled as standard endpoints rather than generic passthrough routes. Additionally, it includes a crucial fix to prevent URL path duplication during proxy URL construction, leading to more robust and correct routing for these new embedding services. Highlights
Changelog
Activity
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully integrates support for Gemini embedContent and OpenAI-compatible /v1/embeddings endpoints. The changes are well-implemented across endpoint path definitions, format detection logic, and URL construction to prevent duplication. The addition of dedicated unit tests for both new functionalities, covering endpoint classification and proxy forwarding behavior, ensures the correctness and reliability of these features. The code is clean, follows established patterns, and directly addresses the stated objectives of the pull request.
🧪 测试结果
总体结果: ✅ 所有测试通过 |
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR.
PR Size: M
- Lines changed: 215
- Files changed: 8
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate
- Code clarity - Good
Automated review by Codex AI
There was a problem hiding this comment.
- Identified the current PR as #931 and applied the label
size/M(215 lines changed across 8 files). - Posted a PR review comment with the summary: No significant issues identified in this PR.
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR. The changes implement embeddings passthrough support for Gemini and OpenAI in a clean, focused manner.
PR Size: M
- Lines changed: 215 (208 additions, 7 deletions)
- Files changed: 8
Changes Overview
- endpoint-paths.ts - Added constant and included in standard endpoint arrays
- format-mapper.ts - Added to OpenAI patterns and action to Gemini patterns
- forwarder.ts - Added to standard endpoint arrays
- url.ts - Added to prevent URL duplication in
- Test files - Added comprehensive tests for the new functionality
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - N/A (no new error paths introduced)
- Type safety - Clean
- Documentation accuracy - Comments updated correctly
- Test coverage - Adequate with 4 new test files
- Code clarity - Good
Automated review by Claude AI
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR. The changes implement embeddings passthrough support for Gemini and OpenAI in a clean, focused manner.
PR Size: M
- Lines changed: 215 (208 additions, 7 deletions)
- Files changed: 8
Changes Overview
- endpoint-paths.ts - Added EMBEDDINGS constant and included in standard endpoint arrays
- format-mapper.ts - Added /v1/embeddings to OpenAI patterns and embedContent action to Gemini patterns
- forwarder.ts - Added /v1/embeddings to standard endpoint arrays
- url.ts - Added /embeddings to prevent URL duplication in buildProxyUrl
- Test files - Added comprehensive tests for the new functionality
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - N/A (no new error paths introduced)
- Type safety - Clean
- Documentation accuracy - Comments updated correctly
- Test coverage - Adequate with 4 new test files
- Code clarity - Good
Automated review by Claude AI
Summary
Support Gemini and OpenAI embeddings passthrough detection, treating
/v1/embeddingsas a standard endpoint with proper URL construction.Problem
The proxy did not recognize:
embedContentendpoints (/v1beta/models/{model}:embedContentand/v1/publishers/google/models/{model}:embedContent)/v1/embeddingsas a standard endpoint (was treated as MCP passthrough)Additionally,
buildProxyUrl()could duplicate/v1/embeddingswhen the provider base URL already included that suffix (similar to the issue fixed in #693 for Gemini).Related PRs:
Solution
embedContentaction to Gemini endpoint detection patterns informat-mapper.ts/v1/embeddingsto standard endpoint lists inendpoint-paths.tsandforwarder.ts/embeddingstotargetEndpointsinurl.tsto prevent URL duplicationAll new embedding paths use passthrough behavior without protocol conversion.
Changes
Core Changes
src/app/v1/_lib/proxy/format-mapper.ts- AddembedContentto Gemini endpoint patternssrc/app/v1/_lib/proxy/endpoint-paths.ts- AddEMBEDDINGStoV1_ENDPOINT_PATHS,STANDARD_ENDPOINT_PATHS,STRICT_STANDARD_ENDPOINT_PATHSsrc/app/v1/_lib/proxy/forwarder.ts- Add/v1/embeddingsto standard endpoint arrayssrc/app/v1/_lib/url.ts- Add/embeddingstotargetEndpointsfor URL deduplicationSupporting Changes
tests/unit/proxy/gemini-embedcontent-format.test.ts- Tests for Gemini embedContent format detectiontests/unit/proxy/openai-embeddings-format.test.ts- Tests for OpenAI embeddings format detectiontests/unit/proxy/openai-embeddings-forwarder.test.ts- Tests for OpenAI embeddings routingtests/unit/app/v1/url.test.ts- Test for buildProxyUrl deduplication with embeddingsTesting
Automated Tests
Verification Commands
```bash
bunx vitest run tests/unit/proxy/gemini-embedcontent-format.test.ts tests/unit/proxy/openai-embeddings-format.test.ts tests/unit/proxy/openai-embeddings-forwarder.test.ts tests/unit/app/v1/url.test.ts
bunx vitest run tests/unit/proxy/provider-selector-format-compatibility.test.ts -t "gemini format rejects claude provider, selects gemini"
bunx vitest run tests/unit/proxy/endpoint-path-normalization.test.ts
bunx @biomejs/biome check src/app/v1/_lib/proxy/format-mapper.ts src/app/v1/_lib/proxy/endpoint-paths.ts src/app/v1/_lib/proxy/forwarder.ts src/app/v1/_lib/url.ts tests/unit/proxy/gemini-embedcontent-format.test.ts tests/unit/proxy/openai-embeddings-format.test.ts tests/unit/proxy/openai-embeddings-forwarder.test.ts tests/unit/app/v1/url.test.ts
```
Notes
Checklist
Description enhanced by Claude AI
Greptile Summary
This PR adds passthrough support for embedding endpoints: Gemini
:embedContent(via both/v1beta/models/...and/v1/publishers/google/models/...) and OpenAI-compatible/v1/embeddings. It correctly registers/v1/embeddingsas a standard endpoint so it is routed through the normal proxy path rather than MCP passthrough, and updatesbuildProxyUrlto avoid duplicating the/embeddingssuffix.:embedContentaction to both Vertex AI and Direct API regex patterns indetectFormatByEndpoint, correctly detected as"gemini"format/v1/embeddings: Registered as a standard and strict-standard endpoint acrossendpoint-paths.ts,forwarder.ts, andformat-mapper.ts; detected as"openai"format/embeddingstotargetEndpointsinurl.tssobuildProxyUrlwon't double-append when the provider base URL already includes itforwarder.tsmaintains its own duplicate copies ofSTANDARD_ENDPOINTSandSTRICT_STANDARD_ENDPOINTSrather than importing fromendpoint-paths.ts— consider consolidating to prevent future driftConfidence Score: 4/5
src/app/v1/_lib/proxy/forwarder.ts— duplicate endpoint lists that have already diverged fromendpoint-paths.tsImportant Files Changed
/v1/embeddingstoV1_ENDPOINT_PATHS,STANDARD_ENDPOINT_PATHS, andSTRICT_STANDARD_ENDPOINT_PATHS. Clean and consistent change.detectFormatByEndpointto recognize/v1/embeddingsas "openai" format and:embedContentaction for both Gemini Vertex AI and Direct API paths. Regex patterns are correct./v1/embeddingsto both localSTANDARD_ENDPOINTSandSTRICT_STANDARD_ENDPOINTSlists, ensuring embeddings requests are not routed via MCP passthrough. These lists duplicateendpoint-paths.tsand have already diverged forresponses/compact./embeddingstotargetEndpoints, enablingbuildProxyUrlto detect when a base URL already contains the embeddings path and avoid duplicating it.buildProxyUrlavoids duplicating/v1/embeddingswhen the base URL already contains it.:embedContentformat detection for both v1beta and Vertex AI paths, plus negative cases for unknown actions and internal paths./v1/embeddingsis detected as "openai" format, classified as standard and strict-standard endpoint, and not classified as raw passthrough./v1/embeddingsrequests are not routed through MCP passthrough URL. Uses internaldoForwardvia type assertion.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Incoming Request] --> B{detectFormatByEndpoint} B -->|/v1/embeddings| C["openai format"] B -->|/v1beta/models/*:embedContent| D["gemini format"] B -->|/v1/publishers/google/models/*:embedContent| D B -->|Other paths| E[Existing routing] C --> F{Is standard endpoint?} F -->|Yes - /v1/embeddings in STANDARD_ENDPOINTS| G[Normal proxy path] F -->|No| H[MCP passthrough path] G --> I{buildProxyUrl} I -->|base URL ends with /embeddings| J[Skip duplicate append] I -->|base URL without /embeddings| K[Standard path concatenation] D --> L[Gemini passthrough handling]Comments Outside Diff (1)
src/app/v1/_lib/proxy/forwarder.ts, line 76-91 (link)Duplicate endpoint lists risk drift
STANDARD_ENDPOINTSandSTRICT_STANDARD_ENDPOINTShere are manually maintained copies ofSTANDARD_ENDPOINT_PATHSandSTRICT_STANDARD_ENDPOINT_PATHSfromendpoint-paths.ts. These two sources have already diverged —STRICT_STANDARD_ENDPOINT_PATHSinendpoint-paths.tsincludes/v1/responses/compact, butSTRICT_STANDARD_ENDPOINTShere does not. Each time a new endpoint like/v1/embeddingsis added, both files must be kept in sync manually. Consider importing fromendpoint-paths.tsto eliminate this duplication:Prompt To Fix All With AI
Last reviewed commit: cbc3624