Class: RubyAmazonBedrock::ResponseBuilders::AmazonText
- Inherits:
-
Object
- Object
- RubyAmazonBedrock::ResponseBuilders::AmazonText
- Defined in:
- lib/bedrock_runtime/response_builders/amazon_text.rb
Overview
The AmazonText class is responsible for parsing and building a structured response from a raw text response. It converts the HTTP response for an Amazon Titan 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 = {}) ⇒ AmazonText
constructor
Initializes a new instance of the Text class.
Constructor Details
#initialize(response, _options = {}) ⇒ AmazonText
Initializes a new instance of the Text class.
12 13 14 |
# File 'lib/bedrock_runtime/response_builders/amazon_text.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/amazon_text.rb', line 22 def build response = JSON.parse(@response.body.read, symbolize_names: true) { text: response[:results]&.first&.dig(:outputText), full_response: response } end |