Class: RubyAmazonBedrock::PayloadBuilders::Amazon::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/bedrock_runtime/payload_builders/amazon/base.rb

Overview

Builds and returns a payload hash suitable for the Amazon model processing. This method constructs a payload with specific parameters like ‘model_id`, `content_type`, `accept`, and a `body` that includes various AI-related settings.

Returns:

  • (Hash)

    The constructed payload containing AI model parameters and settings.

Direct Known Subclasses

TitanTextExpressV1, TitanTextLiteV1

Instance Method Summary collapse

Methods inherited from Base

#initialize, #type

Constructor Details

This class inherits a constructor from RubyAmazonBedrock::PayloadBuilders::Base

Instance Method Details

#buildHash

Builds and returns a hash representing the payload for a text generation request. This method prepares the necessary data structure for processing an input text through a specified model. It includes various configuration parameters for text generation.

Returns:

  • (Hash)

    The method returns a hash with the following key-value pairs:

    • :model_id [String] The identifier for the model that will process the request.

    • :content_type [String] Specifies the content type of the payload, set to ‘application/json’.

    • :accept [String] Indicates the MIME type that the response should conform to.

    • :body [String] A JSON string that includes the following details:

      • :inputText [String] The input text to be processed by the model.

      • :textGenerationConfig [Hash] A hash containing configuration parameters for text generation:

        • :maxTokens [Integer] The maximum number of tokens to generate.

        • :stopSequences [Array<String>] An array of strings that, when encountered, will signal the end

    of generation.

    - :temperature [Float] A parameter controlling the randomness in the response generation.
    - :topP [Float] A parameter controlling the diversity of the generated text.
    


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bedrock_runtime/payload_builders/amazon/base.rb', line 28

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      inputText: @prompt,
      textGenerationConfig: parameters
    }.to_json
  }
end

#model_idObject



40
41
42
# File 'lib/bedrock_runtime/payload_builders/amazon/base.rb', line 40

def model_id
  # noop
end

#parametersObject



44
45
46
47
48
49
50
51
# File 'lib/bedrock_runtime/payload_builders/amazon/base.rb', line 44

def parameters
  {
    maxTokenCount: @options[:max_tokens] || 4096,
    stopSequences: @options[:stop_sequences] || [],
    temperature: @options[:temperature] || 0,
    topP: @options[:top_p] || 1
  }
end