-
-
Notifications
You must be signed in to change notification settings - Fork 433
VertexAI: Add service account key authentication support #532
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
Changes from all commits
9bb3bac
f936e73
5fbe54d
e249746
c06b4bc
e0a321f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ RubyLLM.configure do |config| | |
| config.gemini_api_key = ENV['GEMINI_API_KEY'] | ||
| config.vertexai_project_id = ENV['GOOGLE_CLOUD_PROJECT'] # Available in v1.7.0+ | ||
| config.vertexai_location = ENV['GOOGLE_CLOUD_LOCATION'] | ||
| config.vertexai_service_account_key = ENV['VERTEXAI_SERVICE_ACCOUNT_KEY'] # JSON Key as String from GCP | ||
| config.deepseek_api_key = ENV['DEEPSEEK_API_KEY'] | ||
| config.mistral_api_key = ENV['MISTRAL_API_KEY'] | ||
| config.perplexity_api_key = ENV['PERPLEXITY_API_KEY'] | ||
|
|
@@ -96,6 +97,12 @@ end | |
|
|
||
| These headers are optional and only needed for organization-specific billing or project tracking. | ||
|
|
||
| ### Vertex AI Authentication Configuration | ||
|
|
||
| Google Cloud disallows the creation of Vertex AI API keys for Service Accounts, by default. The recommended way to connect is by using a Service Account's JSON key with appropriate IAM roles or by using Application Default Credentials. | ||
|
|
||
| RubyLLM supports both methods of authenticating to Vertex AI and will only use a Service Account key if the key is provided in the `config.vertexai_service_account_key` configuration field. Otherwise, it will fallback to ADC. | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This frames ADC as a second class choice. Please rephrase to portray both options as equally valid and supported. |
||
| ## Custom Endpoints | ||
|
|
||
| ### OpenAI-Compatible APIs | ||
|
|
@@ -389,6 +396,7 @@ RubyLLM.configure do |config| | |
| config.gemini_api_key = String | ||
| config.vertexai_project_id = String # GCP project ID | ||
| config.vertexai_location = String # e.g., 'us-central1' | ||
| config.vertexai_service_account_key = String # The JSON key as available for GCP Service Accountss | ||
| config.deepseek_api_key = String | ||
| config.mistral_api_key = String | ||
| config.perplexity_api_key = String | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,11 @@ class VertexAI < Gemini | |
| include VertexAI::Models | ||
| include VertexAI::Transcription | ||
|
|
||
| SCOPES = [ | ||
| 'https://www.googleapis.com/auth/cloud-platform', | ||
| 'https://www.googleapis.com/auth/generative-language.retriever' | ||
| ] | ||
|
|
||
| def initialize(config) | ||
| super | ||
| @authorizer = nil | ||
|
|
@@ -36,20 +41,22 @@ def headers | |
|
|
||
| class << self | ||
| def configuration_requirements | ||
| %i[vertexai_project_id vertexai_location] | ||
| %i[vertexai_project_id vertexai_location vertexai_service_account_key] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks ADC only configs by making the service account key a hard requirement and contradicts the intended fallback behaviour of ADC or service account. |
||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def initialize_authorizer | ||
| require 'googleauth' | ||
| @authorizer = ::Google::Auth.get_application_default( | ||
| scope: [ | ||
| 'https://www.googleapis.com/auth/cloud-platform', | ||
| 'https://www.googleapis.com/auth/generative-language.retriever' | ||
| ] | ||
| ) | ||
| @authorizer = if @config.vertexai_service_account_key | ||
| ::Google::Auth::ServiceAccountCredentials.make_creds( | ||
| json_key_io: StringIO.new(@config.vertexai_service_account_key), | ||
| scope: SCOPES | ||
| ) | ||
| else | ||
| ::Google::Auth.get_application_default(scope: SCOPES) | ||
| end | ||
|
Comment on lines
-47
to
+59
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reintroduces the bug fixed by #520 |
||
| rescue LoadError | ||
| raise Error, | ||
| 'The googleauth gem ~> 1.15 is required for Vertex AI. Please add it to your Gemfile: gem "googleauth"' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| config.bedrock_region = 'us-west-2' | ||
| config.bedrock_secret_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', 'test') | ||
| config.bedrock_session_token = ENV.fetch('AWS_SESSION_TOKEN', nil) | ||
| config.vertexai_project_id = ENV.fetch('GOOGLE_CLOUD_PROJECT', 'test-project') | ||
| config.vertexai_location = ENV.fetch('GOOGLE_CLOUD_LOCATION', 'us-central1') | ||
| config.vertexai_service_account_key = ENV.fetch('VERTEXAI_SERVICE_ACCOUNT_KEY', "{ secret_key: 'test' }") | ||
|
Comment on lines
+17
to
+19
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're redefining 2 properties and moving the whole block of vertex ai configs up breaking the sorting. |
||
| config.deepseek_api_key = ENV.fetch('DEEPSEEK_API_KEY', 'test') | ||
| config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', 'test') | ||
| config.gpustack_api_base = ENV.fetch('GPUSTACK_API_BASE', 'http://localhost:11444/v1') | ||
|
|
||
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.
This should be framed as optional when ADC is in place.