Class: Purizumu::Engines::Xai::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/purizumu/engines/xai/response_parser.rb

Overview

Extracts the required tool payload from xAI responses.

Instance Method Summary collapse

Constructor Details

#initialize(response:) ⇒ ResponseParser

Returns a new instance of ResponseParser.



8
9
10
# File 'lib/purizumu/engines/xai/response_parser.rb', line 8

def initialize(response:)
  @response = response
end

Instance Method Details

#translated_textObject



12
13
14
15
16
17
18
19
20
# File 'lib/purizumu/engines/xai/response_parser.rb', line 12

def translated_text
  raise TranslationError, failure_message if response_error?

  extract_translation(parsed_body)
rescue JSON::ParserError => e
  raise TranslationError, "Unable to parse xAI response: #{e.message}"
rescue KeyError => e
  raise TranslationError, "xAI response missing translation payload: #{e.message}"
end