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