Class: Raif::CLI::EvalsReport

Inherits:
Base
  • Object
show all
Defined in:
lib/raif/cli/evals_report.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Raif::CLI::Base

Instance Method Details

#runObject

Rails is deliberately not loaded, for the reason evals:compare does not: this reads one JSON file and renders a template, so booting an app would make it the slowest part of the eval tooling that needs no database or API key.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/raif/cli/evals_report.rb', line 13

def run
  require_relative "../evals/run_report"
  require_relative "../utils/colors"

  format = "html"
  output_path = nil

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: raif evals:report RESULTS.json [options]"

    opts.on("--format FORMAT", Raif::Evals::RunReport::FORMATS,
      "Output format: #{Raif::Evals::RunReport::FORMATS.join(", ")} (default: html)") do |value|
      format = value
    end

    opts.on("--output PATH", "Write to PATH instead of a .html file beside the results file") do |value|
      output_path = value
    end

    opts.on("-h", "--help", "Show this help message") do
      puts opts
      exit
    end
  end

  parse_options!(parser)

  results_path = args.first
  if results_path.nil?
    puts parser
    exit 1
  end

  payload = load_payload(results_path)
  report = Raif::Evals::RunReport.new(payload, label: File.basename(results_path))

  output_path ||= default_output_path(results_path)
  File.write(output_path, report.render(format))

  puts "Run report written to: #{output_path}"
end