Class: Anthropic::Helpers::Vertex::Client
- Inherits:
-
Client
- Object
- Internal::Transport::BaseClient
- Client
- Anthropic::Helpers::Vertex::Client
- Defined in:
- lib/anthropic/helpers/vertex/client.rb
Constant Summary collapse
- DEFAULT_VERSION =
"vertex-2023-10-16"
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, #completions, #models
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(region: ENV["CLOUD_ML_REGION"], project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"], base_url: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY) ⇒ Client
constructor
Creates and returns a new client for interacting with the GCP Vertex API for Anthropic models.
Methods inherited from Client
#calculate_nonstreaming_timeout
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #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: DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY) ⇒ 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
40 41 42 43 44 45 46 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 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 40 def initialize( region: ENV["CLOUD_ML_REGION"], project_id: ENV["ANTHROPIC_VERTEX_PROJECT_ID"], base_url: nil, max_retries: DEFAULT_MAX_RETRIES, timeout: DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: DEFAULT_MAX_RETRY_DELAY ) 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 base_url ||= ENV.fetch( "ANTHROPIC_VERTEX_BASE_URL", @region.to_s == "global" ? "https://aiplatform.googleapis.com/v1" : "https://#{@region}-aiplatform.googleapis.com/v1" ) super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, ) @messages = Anthropic::Resources::Messages.new(client: self) @beta = Anthropic::Resources::Beta.new(client: self) end |
Instance Attribute Details
#beta ⇒ Anthropic::Resources::Beta (readonly)
19 20 21 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 19 def beta @beta end |
#messages ⇒ Anthropic::Resources::Messages (readonly)
16 17 18 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 16 def @messages end |
#project_id ⇒ String (readonly)
13 14 15 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 13 def project_id @project_id end |
#region ⇒ String (readonly)
10 11 12 |
# File 'lib/anthropic/helpers/vertex/client.rb', line 10 def region @region end |