-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Gemini Access via Vertex AI #838
feat: Gemini Access via Vertex AI #838
Conversation
🦋 Changeset detectedLatest commit: a5114b7 The changes in this PR will be included in the next version bump. 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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Not sure I quite follow why the example checks are failing, would you have any ideas? |
@parhammmm you have to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great thanks @parhammmm! Please fix the builld, then we can merge it
packages/core/src/llm/gemini.ts
Outdated
if (options.backend === GEMINI_BACKENDS.VERTEX) | ||
return `${options.location}/${options.project}`; | ||
|
||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess that's not something that should ever happen - throw an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, sure!
packages/core/src/llm/gemini.ts
Outdated
|
||
/* To use Google's Vertex AI backend, it doesn't use api key authentication. | ||
* | ||
* To authenticate for local development: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update https://github.com/run-llama/LlamaIndexTS/blob/main/apps/docs/docs/modules/llms/available_llms/gemini.md and add it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do!
@marcusschiesser I found the issue; it's because Vertex can only be used via the backend and here webpack is attempting to build a node package Have you dealt with such cases before? Update: if someone stumbles on this in the future, the solution is to add the package name to Update 2: also you'll have to make sure the export of the said module is done in |
@marcusschiesser done. I had to restructure the code a little bit to make sure node specific code doesn't break the browser/cloudflare builds.... on to bedrock implementation (pretty close)! |
@marcusschiesser @himself65 how do I use exported items from
UPDATE: Seems like this is only an issue when |
@@ -10,3 +10,6 @@ export { | |||
HuggingFaceEmbedding, | |||
HuggingFaceEmbeddingModelType, | |||
} from "./embeddings/HuggingFaceEmbedding.js"; | |||
|
|||
export { type VertexGeminiSessionOptions } from "./llm/gemini/types.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parhammmm the exports that you add here are only used for NodeJS - so this change means VertexGemini does only work with NodeJS (not edge for example) - if that' ok, nothing to do - otherwise you can send a PR and move this to src/llm/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parhammmm looks great thanks!
@marcusschiesser here's the Vertex implementation. It's a little different than the others because with vertex there isn't any api key auth.
To authenticate for local development:
For production the preferred method is via a service account, more details: https://cloud.google.com/docs/authentication/ . The
GeminiVertexSession
accepts all the params supported byimport { VertexAI } from "@google-cloud/vertexai";
. e.g.Google Auth Options takes all the values from
GoogleAuthOptions
in https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts incase someone wants to directly pass their ownkeyFile
or it's values viacredentials
Once logged in you can test via:
Some notes:
The
@google-cloud/vertexai
sdk is lagging behind@google/generative-ai
, main differences affecting this PR:GenerativeModel.embedContent
from@google/generative-ai
googleapis/nodejs-vertexai#340EnhancedGenerateContentResponse
yet so added the missing pieces here too