Class: Anthropic::Helpers::Vertex::Client
- Inherits:
-
Client
- Object
- Internal::Transport::BaseClient
- Client
- Anthropic::Helpers::Vertex::Client
- Defined in:
- lib/anthropic/helpers/vertex/client.rb,
sig/anthropic/helpers/vertex/client.rbs
Constant Summary
Constants inherited from Client
Client::DEFAULT_INITIAL_RETRY_DELAY, Client::DEFAULT_MAX_RETRIES, Client::DEFAULT_MAX_RETRY_DELAY, Client::DEFAULT_TIMEOUT_IN_SECONDS, Client::MODEL_NONSTREAMING_TOKENS
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #beta ⇒ Anthropic::Resources::Beta readonly
- #messages ⇒ Anthropic::Resources::Messages readonly
- #project_id ⇒ String readonly
- #region ⇒ String readonly
Attributes inherited from Client
#api_key, #auth_token, #credentials, #models, #organization, #token_cache, #webhook_key
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #middleware, #open_telemetry_max_content_bytes, #requester, #timeout
Instance Method Summary collapse
- #files ⇒ bot
-
#initialize(region: ENV["CLOUD_ML_REGION"], project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"], base_url: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: nil, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY, middleware: nil, open_telemetry: nil) ⇒ Client
constructor
Creates and returns a new client for interacting with the GCP Vertex API for Anthropic models.
- #message_threads? ⇒ Boolean private
- #open_telemetry_attributes ⇒ Hash{String=>String} private
- #skills ⇒ bot
- #user_profiles ⇒ bot
Methods inherited from Client
#calculate_nonstreaming_timeout, #retry_request?, #timeout_overridden?
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, #open_telemetry_content?, #open_telemetry_tracer, reap_connection!, #request, #retry_request?, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(region: ENV["CLOUD_ML_REGION"], project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"], base_url: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: nil, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY, middleware: nil, open_telemetry: nil) ⇒ Client
Creates and returns a new client for interacting with the GCP Vertex API for Anthropic models.
GCP credentials are resolved according to Application Default Credentials, described at https://cloud.google.com/docs/authentication/provide-credentials-adc
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 47 def initialize( region: ENV["CLOUD_ML_REGION"], project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"], base_url: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: nil, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY, middleware: nil, open_telemetry: nil ) begin require("googleauth") rescue LoadError = <<~MSG In order to access Anthropic models on Vertex you must require the `googleauth` gem. You can install it by adding the following to your Gemfile: gem "googleauth" and then running `bundle install`. Alternatively, if you are not using Bundler, simply run: gem install googleauth MSG raise RuntimeError.new() end if region.to_s.empty? # rubocop:disable Layout/LineLength = "No region was given. The client should be instantiated with the `region` argument or the `CLOUD_ML_REGION` environment variable should be set." # rubocop:enable Layout/LineLength raise ArgumentError.new() end @region = region if project_id.to_s.empty? # rubocop:disable Layout/LineLength = "No project_id was given and it could not be resolved from credentials. The client should be instantiated with the `project_id` argument or the `ANTHROPIC_VERTEX_PROJECT_ID` environment variable should be set." # rubocop:enable Layout/LineLength raise ArgumentError.new() end @project_id = project_id @authorization = nil base_url = ENV["ANTHROPIC_VERTEX_BASE_URL"] if base_url.to_s.empty? if base_url.to_s.empty? base_url = case @region.to_s when "global" "https://aiplatform.googleapis.com/v1" when "us" "https://aiplatform.us.rep.googleapis.com/v1" when "eu" "https://aiplatform.eu.rep.googleapis.com/v1" else "https://#{@region}-aiplatform.googleapis.com/v1" end end super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, middleware: middleware, open_telemetry: open_telemetry ) @messages = Anthropic::Resources::Messages.new(client: self) @beta = Anthropic::Resources::Beta.new(client: self) end |
Instance Attribute Details
#beta ⇒ Anthropic::Resources::Beta (readonly)
17 18 19 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 17 def beta @beta end |
#messages ⇒ Anthropic::Resources::Messages (readonly)
14 15 16 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 14 def @messages end |
#project_id ⇒ String (readonly)
11 12 13 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 11 def project_id @project_id end |
#region ⇒ String (readonly)
8 9 10 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 8 def region @region end |
Instance Method Details
#files ⇒ bot
139 140 141 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 139 def files raise NotImplementedError, "Files are not supported on Vertex." end |
#message_threads? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
137 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 137 def = false |
#open_telemetry_attributes ⇒ Hash{String=>String}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
205 206 207 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 205 def open_telemetry_attributes {**super, Anthropic::Internal::Tracing::GEN_AI_PROVIDER_NAME => "gcp.vertex_ai"} end |
#skills ⇒ bot
143 144 145 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 143 def skills raise NotImplementedError, "Skills are not supported on Vertex." end |
#user_profiles ⇒ bot
147 148 149 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 147 def user_profiles raise NotImplementedError, "Managing user profiles is not supported on Vertex." end |