Sha256: 512fe678bf2c6f745bf573b377831e661e7172f47fcf3a78e4ada98c3e55698d
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require 'base64' require 'aws-sdk-bedrockruntime' require 'bedrock_runtime/payload_factory' require 'bedrock_runtime/response_factory' module RubyAmazonBedrock # 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. class Client # Initializes the AWS BedrockRuntime client. # # @note The AWS credentials and region are fetched from the environment variables. def initialize(region: nil, access_key_id: nil, secret_access_key: nil) config = RubyAmazonBedrock.configuration || RubyAmazonBedrock::Configuration.new @client = 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 # Invokes a model using the Bedrock Runtime client. # # @param id [String] The ID of the model to be invoked. # @param prompt [String] The prompt string for what needs to be generated. # @param options [Hash] Additional options for the model invocation. # @return [Aws::BedrockRuntime::Types::InvokeModelOutput] The output from invoking the model. # @example Invoke a model with specific ID and input # client = RubyAmazonBedrock::Client.new # client.invoke_model( # id: 'model_id', prompt: 'This is what you want to generate', options: { option_key: 'option_value' } # ) def invoke_model(id:, prompt:, options: {}) payload_builder_class = RubyAmazonBedrock::PayloadFactory.new(id, prompt, options).create response = @client.invoke_model(payload_builder_class.build) response_builder_class = RubyAmazonBedrock::ResponseFactory.new(payload_builder_class.type, response, options).create response_builder_class.build end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-amazon-bedrock-0.2.2 | lib/bedrock_runtime/client.rb |