Class: RubyAmazonBedrock::PayloadFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/bedrock_runtime/payload_factory.rb

Overview

The PayloadFactory class is responsible for creating instances of payload builders based on the provided model identifier.

Attributes:

  • model_id [String]: The identifier of the model.

  • input [String]: The input string for what needs to be generated.

  • options [Hash]: Additional options for payload creation.

Instance Method Summary collapse

Constructor Details

#initialize(model_id, input, options = {}) ⇒ PayloadFactory

Returns a new instance of PayloadFactory.



32
33
34
35
36
# File 'lib/bedrock_runtime/payload_factory.rb', line 32

def initialize(model_id, input, options = {})
  @model_id = model_id
  @prompt = input
  @options = options
end

Instance Method Details

#createHash

Creates a payload using the appropriate builder based on the model identifier.

Returns:

  • (Hash)

    The built payload.

Raises:



42
43
44
45
46
47
48
# File 'lib/bedrock_runtime/payload_factory.rb', line 42

def create
  builder_class = models_to_builders[@model_id]

  raise UnknownModelError, "Unknown modelId: #{@model_id}" unless builder_class

  builder_class.new(@prompt, @options)
end

#models_to_buildersHash

Defines a mapping from model identifiers to their respective builder classes.

Returns:

  • (Hash)

    The mapping of model identifiers to builder classes.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bedrock_runtime/payload_factory.rb', line 53

def models_to_builders
  {
    'ai21.j2-mid-v1' => PayloadBuilders::Ai21Labs::J2MidV1,
    'ai21.j2-ultra-v1' => PayloadBuilders::Ai21Labs::J2UltraV1,
    'amazon.titan-image-generator-v1' => PayloadBuilders::Amazon::TitanImageGeneratorV1,
    'amazon.titan-text-lite-v1' => PayloadBuilders::Amazon::TitanTextLiteV1,
    'amazon.titan-text-express-v1' => PayloadBuilders::Amazon::TitanTextExpressV1,
    'anthropic.claude-instant-v1' => PayloadBuilders::Anthropic::ClaudeInstantV1,
    'anthropic.claude-v1' => PayloadBuilders::Anthropic::ClaudeV1,
    'anthropic.claude-v2' => PayloadBuilders::Anthropic::ClaudeV2,
    'cohere.command-light-text-v14' => PayloadBuilders::Cohere::CommandLightTextV14,
    'cohere.command-text-v14' => PayloadBuilders::Cohere::CommandTextV14,
    'cohere.embed-english-v3' => PayloadBuilders::Cohere::EmbedEnglishV3,
    'cohere.embed-multilingual-v3' => PayloadBuilders::Cohere::EmbedMultilingualV3,
    'meta.llama2-13b-chat-v1' => PayloadBuilders::Meta::Llama213bChatV1,
    'meta.llama2-70b-chat-v1' => PayloadBuilders::Meta::Llama270bChatV1,
    'meta.llama3-70b-instruct-v1:0' => PayloadBuilders::Meta::Llama370bInstructV1,
    'meta.llama3-8b-instruct-v1:0' => PayloadBuilders::Meta::Llama38bInstructV1,
    'stability.stable-diffusion-xl-v0' => PayloadBuilders::StabilityAi::StableDiffusionXlV0,
    'stability.stable-diffusion-xl-v1' => PayloadBuilders::StabilityAi::StableDiffusionXlV1
  }
end