Class: RubyAmazonBedrock::PayloadBuilders::Meta::Base

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

Overview

Builds and returns a payload hash suitable for the Meta 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.

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

Constructs and returns a payload formatted for text generation requests. This method assembles the necessary data structure for processing text input through an AI model, with various parameters to guide the generation process.

Returns:

  • (Hash)

    A structured payload containing:

    • :model_id [String] Identifier for the AI model that will process the text generation request.

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

    • :accept [String] Indicates the MIME type for the expected response.

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

      • :prompt [String] The input text for the model to generate content from.

      • :max_gen_len [Integer] Maximum length for the generated content, measured in tokens.

      • :temperature [Float] A parameter controlling the randomness in the generated content.

      • :top_p [Float] Nucleus sampling parameter controlling the diversity of the generated text.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bedrock_runtime/payload_builders/meta/base.rb', line 25

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      prompt: @prompt,
      max_gen_len: parameters[:max_gen_len],
      temperature: parameters[:temperature],
      top_p: parameters[:top_p]
    }.to_json
  }
end

#model_idObject



39
40
41
# File 'lib/bedrock_runtime/payload_builders/meta/base.rb', line 39

def model_id
  # noop
end

#parametersObject



43
44
45
46
47
48
49
# File 'lib/bedrock_runtime/payload_builders/meta/base.rb', line 43

def parameters
  {
    max_gen_len: @options[:max_tokens] || 512,
    temperature: @options[:temperature] || 0.5,
    top_p: @options[:top_p] || 0.9
  }
end