Class: RubyAmazonBedrock::PayloadBuilders::Cohere::CommandBase

Inherits:
Base
  • Object
show all
Defined in:
lib/bedrock_runtime/payload_builders/cohere/command_base.rb

Overview

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

CommandLightTextV14, CommandTextV14

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 command generation requests. This method prepares the data necessary for processing a command input through a specified AI model. It configures several parameters to control the behavior and output of the model in response to the command.

Returns:

  • (Hash)

    A hash containing the necessary information for command processing:

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

    • :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:

      • :prompt [String] The command input to be processed by the model.

      • :maxTokens [Integer] The maximum number of tokens the model should generate in response.

      • :temperature [Float] A parameter controlling the variability in the model’s responses.

      • :return_likelihood [String] Indicates whether the response should include likelihood information.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bedrock_runtime/payload_builders/cohere/command_base.rb', line 26

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      prompt: "#{@prompt}:",
      temperature: parameters[:temperature],
      p: parameters[:p],
      k: parameters[:k],
      max_tokens: parameters[:max_tokens],
      num_generations: parameters[:num_generations],
      return_likelihoods: parameters[:return_likelihoods],
      stop_sequences: parameters[:stop_sequences],
      stream: parameters[:stream],
      truncate: parameters[:truncate]
    }.to_json
  }
end

#model_idObject



46
47
48
# File 'lib/bedrock_runtime/payload_builders/cohere/command_base.rb', line 46

def model_id
  # noop
end

#parametersObject

rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bedrock_runtime/payload_builders/cohere/command_base.rb', line 50

def parameters # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  {
    temperature: @options[:temperature] || 0.9,
    p: @options[:top_p] || 0.75,
    k: @options[:top_k] || 0,
    max_tokens: @options[:max_tokens] || 20,
    num_generations: @options[:num_generations] || 1,
    return_likelihoods: @options[:return_likelihoods] || 'GENERATION',
    stop_sequences: @options[:stop_sequences] || [],
    stream: @options[:stream] || false,
    # logit_bias: @options[:logit_bias] || {},
    truncate: @options[:truncate] || 'NONE'
  }
end