Class: RubyAmazonBedrock::ResponseBuilders::Ai21Labs
- Inherits:
-
Object
- Object
- RubyAmazonBedrock::ResponseBuilders::Ai21Labs
- Defined in:
- lib/bedrock_runtime/response_builders/ai_21_labs.rb
Overview
The Ai21Labs class is responsible for parsing and building a structured response from a raw text response. It converts the HTTP response for an AI21 Labs model into a structured format to make it easier to access the response data.
Instance Method Summary collapse
-
#build ⇒ Hash
Builds and returns a structured representation of the raw text response.
-
#initialize(response, _options = {}) ⇒ Ai21Labs
constructor
Initializes a new instance of the Text class.
Constructor Details
#initialize(response, _options = {}) ⇒ Ai21Labs
Initializes a new instance of the Text class.
12 13 14 |
# File 'lib/bedrock_runtime/response_builders/ai_21_labs.rb', line 12 def initialize(response, = {}) @response = response end |
Instance Method Details
#build ⇒ Hash
Builds and returns a structured representation of the raw text response. This method parses the raw response body as JSON and symbolizes the names for easier access in Ruby.
The keys of the hash are symbolized for convenient access.
22 23 24 25 26 27 28 29 |
# File 'lib/bedrock_runtime/response_builders/ai_21_labs.rb', line 22 def build response = JSON.parse(@response.body.read, symbolize_names: true) { text: response[:completions]&.first&.dig(:data, :text), full_response: response } end |