Skip to content
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

Google Vertex API support #950

Merged
merged 7 commits into from
Apr 2, 2024
Merged

Conversation

madppiper
Copy link
Contributor

This commit adds support for the google cloud vertex API. It relies on https://github.com/googleapis/nodejs-vertexai to connect.

To enable:

  1. Select or create a Google Cloud project.
  2. Enable billing for your project.
  3. Enable the Vertex AI API.
  4. Set up authentication with a service account
    so you can access the API from your local workstation.

The service account credentials file can be imported as an environmental variable:

    GOOGLE_APPLICATION_CREDENTIALS = clientid.json

Make sure docker has access to the file. Afterwards Google Vertex endpoints can be configured as following:

MODELS=`[
//...
    {
       "name": "gemini-1.0-pro", //model-name
       "displayName": "Vertex code-bison",
       "location": "europe-west3",
       "apiEndpoint": "", //alternative api endpoint url
       "endpoints" : [{
         "type": "vertex"
       }]
     },
]`

Tested locally, but I had to merge it over to a new branch, to make the reviewing process easier - so please evaluate. Setting up the google permissions can be a bit tricky and model availability can differ for location & your own access level. So beware of this if a connection fails.

Google Application credentials can be set via

GOOGLE_APPLICATION_CREDENTIALS = clientid.json
Fixed minor issues
@nsarrazin nsarrazin self-requested a review March 22, 2024 08:24
@nsarrazin
Copy link
Collaborator

Hi! Thanks for the contribution, I'll take a look soon 😄

@madppiper
Copy link
Contributor Author

Hi! Thanks for the contribution, I'll take a look soon 😄

No problem - you guys are doing a fantastic job. Let me know if this requires any improvements.

Copy link
Collaborator

@nsarrazin nsarrazin left a comment

Choose a reason for hiding this comment

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

First of all thanks for the PR! It looks great 🤗

Two small things I noticed:

  • Could you run npm run format so the linter checks pass? 😁
  • Can you install @google-cloud/vertexai as an optional dependency like for the other endpoints?

And I was wondering, would it be bad practice to put the content of the JSON credentials into an env variable secret rather than specifying the file path and reading the file? Trying to read the file could cause quite some headaches with different infra & docker setups I imagine, but not sure if it's safe to just pass the JSON content directly.

@madppiper
Copy link
Contributor Author

Two small things I noticed:

  • Could you run npm run format so the linter checks pass? 😁
  • Can you install @google-cloud/vertexai as an optional dependency like for the other endpoints?

Yea, of course. I just pushed both.

And I was wondering, would it be bad practice to put the content of the JSON credentials into an env variable secret rather than specifying the file path and reading the file? Trying to read the file could cause quite some headaches with different infra & docker setups I imagine, but not sure if it's safe to just pass the JSON content directly.

I agree and I am not a fan either. But I checked against the google docs and it was my impression that the json file was the standard way of doing it with google. Personally I would have preferred an apiToken (which funnily enough you can generate, but isn't supported by the node api of theirs):

googleapis/nodejs-vertexai#197

This is the doc in question:
https://cloud.google.com/docs/authentication/application-default-credentials#GAC

GOOGLE_APPLICATION_CREDENTIALS environment variable
You can use the GOOGLE_APPLICATION_CREDENTIALS environment variable to provide the location of a credential JSON file. This JSON file can be one of the following types of files: ...

I should mention: there are still a few things untested from my part - though connecting to Gemini-Pro works, I couldn't test it with any other model, nor could I set up a custom endpoint, as I was lacking an account with the proper privileges and or available resources. So i did the apiUrl implementation blindly.

It could also use a more thorough test of the parameters. In principle it should work, but I only tested it as far as it was required from our end.

@analyticsrepo01
Copy link

Awesome, +1 to check if merge is approved

Copy link
Collaborator

@nsarrazin nsarrazin left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation! 😄 I think we can merge this now, looks good to me

@nsarrazin nsarrazin merged commit 3ebd3a8 into huggingface:main Apr 2, 2024
3 checks passed
@nsarrazin
Copy link
Collaborator

lol you got double approved apparently 😆 thanks for the contribution!

@madppiper
Copy link
Contributor Author

lol you got double approved apparently 😆 thanks for the contribution!

Haha, I'll start using that in my resume from now on

My contributions were "double approved"

ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
* Added Google Vertex API support

Google Application credentials can be set via

GOOGLE_APPLICATION_CREDENTIALS = clientid.json

* Updated the readme file

* Updated the package-lock file

* Updated the package-lock file
Fixed minor issues

* Moved "@google-cloud/vertexai" to optional dependencies

* Updated for lint checker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants