Class: Anthropic::Helpers::Bedrock::Client
- Inherits:
-
Client
- Object
- Internal::Transport::BaseClient
- Client
- Anthropic::Helpers::Bedrock::Client
- Defined in:
- lib/anthropic/helpers/bedrock/client.rb
Constant Summary collapse
- DEFAULT_VERSION =
"bedrock-2023-05-31"
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
- #aws_credentials ⇒ Aws::Credentials readonly
- #aws_region ⇒ String readonly
- #beta ⇒ Anthropic::Resources::Beta readonly
- #completions ⇒ Anthropic::Resources::Completions readonly
- #messages ⇒ Anthropic::Resources::Messages readonly
Attributes inherited from Client
#api_key, #auth_token, #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(aws_region: nil, base_url: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, aws_access_key: nil, aws_secret_key: nil, aws_session_token: nil, aws_profile: nil) ⇒ Client
constructor
Creates and returns a new client for interacting with the AWS Bedrock 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(aws_region: nil, base_url: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, aws_access_key: nil, aws_secret_key: nil, aws_session_token: nil, aws_profile: nil) ⇒ Client
Creates and returns a new client for interacting with the AWS Bedrock API for Anthropic models.
AWS credentials are resolved according to the AWS SDK’s default resolution order, described at
https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html#credchain or https://github.com/aws/aws-sdk-ruby?tab=readme-ov-file#configuration
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 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 50 def initialize( aws_region: nil, base_url: nil, max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, aws_access_key: nil, aws_secret_key: nil, aws_session_token: nil, aws_profile: nil ) begin require("aws-sdk-bedrockruntime") rescue LoadError = <<~MSG In order to access Anthropic models on Bedrock you must require the `aws-sdk-bedrockruntime` gem. You can install it by adding the following to your Gemfile: gem "aws-sdk-bedrockruntime" and then running `bundle install`. Alternatively, if you are not using Bundler, simply run: gem install aws-sdk-bedrockruntime MSG raise RuntimeError.new() end @aws_region, @aws_credentials = resolve_region_and_credentials( aws_region: aws_region, aws_secret_key: aws_secret_key, aws_access_key: aws_access_key, aws_session_token: aws_session_token, aws_profile: aws_profile ) @signer = Aws::Sigv4::Signer.new( service: "bedrock", region: @aws_region, credentials: @aws_credentials ) base_url ||= ENV.fetch( "ANTHROPIC_BEDROCK_BASE_URL", "https://bedrock-runtime.#{@aws_region}.amazonaws.com" ) 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) @completions = Anthropic::Resources::Completions.new(client: self) @beta = Anthropic::Resources::Beta.new(client: self) end |
Instance Attribute Details
#aws_credentials ⇒ Aws::Credentials (readonly)
22 23 24 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 22 def aws_credentials @aws_credentials end |
#aws_region ⇒ String (readonly)
19 20 21 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 19 def aws_region @aws_region end |
#beta ⇒ Anthropic::Resources::Beta (readonly)
16 17 18 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 16 def beta @beta end |
#completions ⇒ Anthropic::Resources::Completions (readonly)
13 14 15 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 13 def completions @completions end |
#messages ⇒ Anthropic::Resources::Messages (readonly)
10 11 12 |
# File 'lib/anthropic/helpers/bedrock/client.rb', line 10 def @messages end |