Class: Braintrust::Eval::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/eval/result.rb

Overview

Result represents the outcome of an evaluation run Contains experiment metadata, errors, timing information, and raw score data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment_id:, experiment_name:, project_id:, project_name:, permalink:, errors:, duration:, scores: nil) ⇒ Result

Create a new result

Parameters:

  • experiment_id (String)

    The experiment ID

  • experiment_name (String)

    The experiment name

  • project_id (String)

    The project ID

  • project_name (String)

    The project name

  • permalink (String)

    Link to view the experiment in Braintrust UI

  • errors (Array<String>)

    List of errors that occurred

  • duration (Float)

    Duration in seconds

  • scores (Hash, nil) (defaults to: nil)

    Raw score data { scorer_name => Array<Numeric> }



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/braintrust/eval/result.rb', line 23

def initialize(experiment_id:, experiment_name:, project_id:, project_name:,
  permalink:, errors:, duration:, scores: nil)
  @experiment_id = experiment_id
  @experiment_name = experiment_name
  @project_id = project_id
  @project_name = project_name
  @permalink = permalink
  @errors = errors
  @duration = duration
  @scores = scores
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def duration
  @duration
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def errors
  @errors
end

#experiment_idObject (readonly)

Returns the value of attribute experiment_id.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def experiment_id
  @experiment_id
end

#experiment_nameObject (readonly)

Returns the value of attribute experiment_name.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def experiment_name
  @experiment_name
end

Returns the value of attribute permalink.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def permalink
  @permalink
end

#project_idObject (readonly)

Returns the value of attribute project_id.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def project_id
  @project_id
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def project_name
  @project_name
end

#scoresObject (readonly)

Returns the value of attribute scores.



11
12
13
# File 'lib/braintrust/eval/result.rb', line 11

def scores
  @scores
end

Instance Method Details

#failed?Boolean

Check if the evaluation failed (has errors)

Returns:

  • (Boolean)


43
44
45
# File 'lib/braintrust/eval/result.rb', line 43

def failed?
  !success?
end

#scorer_statsHash<String, ScorerStats>

Get statistics for all scorers (lazily computed from scores)

Returns:

  • (Hash<String, ScorerStats>)

    Scorer stats keyed by scorer name



74
75
76
# File 'lib/braintrust/eval/result.rb', line 74

def scorer_stats
  @scorer_stats ||= build_scorer_stats
end

#success?Boolean

Check if the evaluation was successful (no errors)

Returns:

  • (Boolean)


37
38
39
# File 'lib/braintrust/eval/result.rb', line 37

def success?
  errors.empty?
end

#summaryExperimentSummary

Get the experiment summary (lazily computed)

Returns:



49
50
51
# File 'lib/braintrust/eval/result.rb', line 49

def summary
  @summary ||= build_summary
end

#to_prettyString

Format the result as a pretty CLI output with box drawing and colors

Returns:

  • (String)


68
69
70
# File 'lib/braintrust/eval/result.rb', line 68

def to_pretty
  Formatter.format_experiment_summary(summary)
end

#to_sString

Format the result as a human-readable string (Go SDK format)

Returns:

  • (String)


55
56
57
58
59
60
61
62
63
64
# File 'lib/braintrust/eval/result.rb', line 55

def to_s
  [
    "Experiment: #{experiment_name}",
    "Project: #{project_name}",
    "ID: #{experiment_id}",
    "Link: #{permalink}",
    "Duration: #{duration.round(4)}s",
    "Errors: #{errors.length}"
  ].join("\n")
end