Sha256: d19dde088a4fe481c833f866efb76c529bbdba7f8cc8e3a340735bc070bdb617

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'aws-sdk-bedrockruntime'

require 'bedrock_runtime/payload_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:, access_key_id:, secret_access_key:)
      @client = Aws::BedrockRuntime::Client.new(
        region: region,
        access_key_id: access_key_id,
        secret_access_key: secret_access_key
      )
    end

    # Invokes a model using the Bedrock Runtime client.
    #
    # @param id [String] The ID of the model to be invoked.
    # @param input [String] The input 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', input: 'This is what you want to generate', options: { option_key: 'option_value' }
    # 	)
    def invoke_model(id:, input:, options: {})
      payload_builder_class = RubyAmazonBedrock::PayloadFactory.new(id, input, options).create
      response = @client.invoke_model(payload_builder_class.build)
      JSON.parse(response.body.read, symbolize_names: true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-amazon-bedrock-0.1.1 lib/bedrock_runtime/client.rb