Class: ActiveHarness::OutputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/active_harness/pipeline/output_parser.rb

Overview

Parses the raw model response into the declared output type.

Instance Method Summary collapse

Constructor Details

#initialize(output_type, schema: nil) ⇒ OutputParser

Returns a new instance of OutputParser.



6
7
8
9
# File 'lib/active_harness/pipeline/output_parser.rb', line 6

def initialize(output_type, schema: nil)
  @output_type = output_type
  @schema      = schema
end

Instance Method Details

#parse(content) ⇒ String | Hash

Parameters:

  • content (String)

Returns:

  • (String | Hash)


13
14
15
16
17
18
19
# File 'lib/active_harness/pipeline/output_parser.rb', line 13

def parse(content)
  case @output_type
  when :text then parse_text(content)
  when :json then parse_json(content)
  else raise Errors::ConfigurationError, "Unknown output type: #{@output_type.inspect}"
  end
end