Class: RubyAmazonBedrock::Client
- Inherits:
-
Object
- Object
- RubyAmazonBedrock::Client
- Defined in:
- lib/bedrock_runtime/client.rb
Overview
Client for interfacing with the Amazon Bedrock Runtime.
This class provides methods to initialize a client for AWS BedrockRuntime and to invoke a model using the client.
Instance Method Summary collapse
-
#initialize(region: nil, access_key_id: nil, secret_access_key: nil, profile: nil) ⇒ Client
constructor
Initializes the AWS BedrockRuntime client.
-
#invoke_model(id:, prompt:, options: {}) ⇒ Aws::BedrockRuntime::Types::InvokeModelOutput
Invokes a model using the Bedrock Runtime client.
Constructor Details
#initialize(region: nil, access_key_id: nil, secret_access_key: nil, profile: nil) ⇒ Client
Note:
The AWS credentials and region are fetched from the environment variables.
Initializes the AWS BedrockRuntime client.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bedrock_runtime/client.rb', line 17 def initialize(region: nil, access_key_id: nil, secret_access_key: nil, profile: nil) config = RubyAmazonBedrock.configuration || RubyAmazonBedrock::Configuration.new @client = if profile Aws::BedrockRuntime::Client.new( profile: profile ) else Aws::BedrockRuntime::Client.new( region: region || config.region, access_key_id: access_key_id || config.access_key_id, secret_access_key: secret_access_key || config.secret_access_key ) end end |
Instance Method Details
#invoke_model(id:, prompt:, options: {}) ⇒ Aws::BedrockRuntime::Types::InvokeModelOutput
Invokes a model using the Bedrock Runtime client.
)
44 45 46 47 48 49 50 |
# File 'lib/bedrock_runtime/client.rb', line 44 def invoke_model(id:, prompt:, options: {}) payload_builder_class = RubyAmazonBedrock::PayloadFactory.new(id, prompt, ).create response = @client.invoke_model(payload_builder_class.build) response_builder_class = RubyAmazonBedrock::ResponseFactory.new(id, response, ).create response_builder_class.build end |