Skip to content

Conversation

@ashktn
Copy link
Contributor

@ashktn ashktn commented Apr 28, 2025

Moving to @google/genai and reusing the gemini provider when using gemini on vertex ai

Context

Use the gemini provider when using a gemini model is selected on vertex ai.
@google/genai now support both Google Gemini and Vertex AI APIs
Prompt caching is already implemented in the gemini provider

Implementation

Used the gemini provider when a gemini model is selected on vertex ai.

Screenshots

Screen.Recording.2025-04-28.at.00.02.30.mov

How to Test

Select a gemini model that supports prompt caching on vertex ai. enable prompt caching

Get in Touch

ashktn


Important

Integrates Gemini prompt caching on Vertex AI by using GeminiHandler, updating models, and modifying tests and configurations.

  • Behavior:
    • Integrates GeminiHandler for prompt caching with Gemini models on Vertex AI in vertex.ts and gemini.ts.
    • Updates vertexModels in api.ts to support prompt caching for Gemini models.
    • Removes @google-cloud/vertexai dependency from package.json.
  • Testing:
    • Updates vertex.test.ts to mock GeminiHandler and test prompt caching behavior.
    • Removes vertex-gemini-format.test.ts and vertex-gemini-format.ts as they are no longer needed.
  • Configuration:
    • Adds isVertex option to ProviderSettings in roo-code.d.ts, types.ts, and schemas/index.ts to distinguish between Gemini and Vertex AI usage.

This description was created by Ellipsis for f867837e867308b3e74f0cd15bf6701537d34b83. You can customize this summary. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Apr 28, 2025

🦋 Changeset detected

Latest commit: 77e4df6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Apr 28, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider wrapping JSON.parse(this.options.vertexJsonCredentials) in a try/catch block to handle potential JSON parsing errors. This improves resiliency if invalid credentials are provided.

This comment was generated because it violated a code review rule: mrule_OR1S8PRRHcvbdFib.

Moving to @google/genai and reusing the gemini provider when using gemini on vertex ai
@ashktn ashktn force-pushed the feat/vertex-gemini-caching branch from f867837 to 96b7921 Compare April 28, 2025 11:23
@adamhill
Copy link
Contributor

Thanks for tackling this difficult problem!

Even though you don't think it is perfect. We don't have to eat the elephant all in on bite. The whole troop can work on improving it now. 🦘❤️

Adding your comment from the channel Thread for completeness:

It seems like the right direction to use the @google/genai lib over @google-cloud/vertexai since google is encouraging using genai. The new lib says it works for Gemini 2.0, but i had no issues using Gemini 1.5

From a code structure perspective, it just didn't feel clean importing one provider from the other provider. As a future refactor task, we could move the common gemini code to a new file and then import that file in both providers

@mrubens
Copy link
Collaborator

mrubens commented Apr 28, 2025

@cte are you able to review this one? Thanks!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 28, 2025
@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap Apr 28, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 28, 2025
Copy link
Collaborator

@cte cte left a comment

Choose a reason for hiding this comment

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

I moved some stuff around; LMK if you any questions about my changes.

@ashktn
Copy link
Contributor Author

ashktn commented Apr 28, 2025

I moved some stuff around; LMK if you any questions about my changes.

looks great!

@ashktn
Copy link
Contributor Author

ashktn commented Apr 28, 2025

minor: seems like gemini-2.5-flash-preview-04-17 supports caching as per this doc- could be different between gemini vs vertex
https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview#supported_models

@cte cte merged commit a3d8c0e into RooCodeInc:main Apr 28, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from PR [Pre Approval Review] to Done in Roo Code Roadmap Apr 28, 2025
shariqriazz pushed a commit to shariqriazz/Roo-Code that referenced this pull request Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants