Class: RubyAmazonBedrock::PayloadBuilders::Anthropic::Base

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

Overview

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

Direct Known Subclasses

ClaudeInstantV1, ClaudeV1, ClaudeV2

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 hash for text generation requests. This method is designed to prepare a structured payload comprising various parameters that dictate how the input text should be processed by the models.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bedrock_runtime/payload_builders/anthropic/base.rb', line 30

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      prompt: "\n\nHuman: #{@prompt}\n\nAssistant:",
      max_tokens_to_sample: parameters[:max_tokens_to_sample],
      temperature: parameters[:temperature],
      top_k: parameters[:top_k],
      top_p: parameters[:top_p],
      stop_sequences: parameters[:stop_sequences],
      anthropic_version: 'bedrock-2023-05-31'
    }.to_json
  }
end

#model_idObject



47
48
49
# File 'lib/bedrock_runtime/payload_builders/anthropic/base.rb', line 47

def model_id
  # noop
end

#parametersObject



51
52
53
54
55
56
57
58
59
# File 'lib/bedrock_runtime/payload_builders/anthropic/base.rb', line 51

def parameters
  {
    max_tokens_to_sample: @options[:max_tokens] || 200,
    temperature: @options[:temperature] || 0.5,
    top_k: @options[:top_k] || 250,
    top_p: @options[:top_p] || 1,
    stop_sequences: @options[:stop_sequences] || ['\n\nHuman']
  }
end