Class: RubyAmazonBedrock::ResponseBuilders::Anthropic

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

Overview

The Anthropic class is responsible for parsing and building a structured response from a raw text response. It converts the HTTP response for an Anthropic model into a structured format to make it easier to access the response data.

Instance Method Summary collapse

Constructor Details

#initialize(response, _options = {}) ⇒ Anthropic

Initializes a new instance of the Text class.

Parameters:

  • response (Object)

    The raw response object with is an HTTP response.



12
13
14
# File 'lib/bedrock_runtime/response_builders/anthropic.rb', line 12

def initialize(response, _options = {})
  @response = response
end

Instance Method Details

#buildHash

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.

Returns:

  • (Hash)

    A hash representing the structured data from the response body.



22
23
24
25
26
27
28
29
# File 'lib/bedrock_runtime/response_builders/anthropic.rb', line 22

def build
  response = JSON.parse(@response.body.read, symbolize_names: true)

  {
    text: response[:completion],
    full_response: response
  }
end