Class: RubyAmazonBedrock::ResponseFactory
- Inherits:
-
Object
- Object
- RubyAmazonBedrock::ResponseFactory
- Defined in:
- lib/bedrock_runtime/response_factory.rb
Overview
The ResponseFactory class is a factory for creating different types of response builder objects. It is designed to instantiate and return an object of a specific response builder class
Instance Method Summary collapse
-
#create ⇒ ResponseBuilders::Class
Creates and returns an instance of the specified response builder.
-
#initialize(model_id, response, options = {}) ⇒ ResponseFactory
constructor
Initializes a new instance of the ResponseFactory class.
-
#models_to_builders ⇒ Hash
Defines a mapping from model identifiers to their respective builder classes.
Constructor Details
#initialize(model_id, response, options = {}) ⇒ ResponseFactory
Initializes a new instance of the ResponseFactory class.
21 22 23 24 25 |
# File 'lib/bedrock_runtime/response_factory.rb', line 21 def initialize(model_id, response, = {}) @model_id = model_id @response = response @options = end |
Instance Method Details
#create ⇒ ResponseBuilders::Class
Creates and returns an instance of the specified response builder. This method uses the @type instance variable to determine which type of response builder to instantiate and return.
it returns an instance of any of the response builder classes. Returns nil if the model_id does not match any known response builders.
34 35 36 37 |
# File 'lib/bedrock_runtime/response_factory.rb', line 34 def create builder_class = models_to_builders[@model_id] builder_class.new(@response, @options) end |
#models_to_builders ⇒ Hash
Defines a mapping from model identifiers to their respective builder classes.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bedrock_runtime/response_factory.rb', line 42 def models_to_builders { 'ai21.j2-mid-v1' => ResponseBuilders::Ai21Labs, 'ai21.j2-ultra-v1' => ResponseBuilders::Ai21Labs, 'amazon.titan-image-generator-v1' => ResponseBuilders::AmazonImage, 'amazon.titan-text-lite-v1' => ResponseBuilders::AmazonText, 'amazon.titan-text-express-v1' => ResponseBuilders::AmazonText, 'anthropic.claude-instant-v1' => ResponseBuilders::Anthropic, 'anthropic.claude-v1' => ResponseBuilders::Anthropic, 'anthropic.claude-v2' => ResponseBuilders::Anthropic, 'cohere.command-light-text-v14' => ResponseBuilders::CohereCommand, 'cohere.command-text-v14' => ResponseBuilders::CohereCommand, 'cohere.embed-english-v3' => ResponseBuilders::CohereEmbed, 'cohere.embed-multilingual-v3' => ResponseBuilders::CohereEmbed, 'meta.llama2-13b-chat-v1' => ResponseBuilders::Meta, 'meta.llama2-70b-chat-v1' => ResponseBuilders::Meta, 'meta.llama3-70b-instruct-v1:0' => ResponseBuilders::Meta, 'meta.llama3-8b-instruct-v1:0' => ResponseBuilders::Meta, 'stability.stable-diffusion-xl-v0' => ResponseBuilders::StabilityAi, 'stability.stable-diffusion-xl-v1' => ResponseBuilders::StabilityAi } end |