Class: LLM::Eval
- Inherits:
-
Object
- Object
- LLM::Eval
- Extended by:
- FileUtils
- Includes:
- Run
- Defined in:
- lib/llm/eval.rb,
lib/llm/eval/run.rb,
lib/llm/eval/tracer.rb
Overview
The Eval class represents an eval for a given provider, and path to an eval.rb file that describes the eval.
Defined Under Namespace
Constant Summary collapse
- File =
::File
- UNDEFINED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new
Instance Attribute Summary collapse
- #sample ⇒ Integer readonly
- #steps ⇒ Array<String> readonly
- #llm ⇒ LLM::Provider readonly
- #model ⇒ String readonly
- #root ⇒ String readonly
-
#penalties ⇒ Array<Hash>
readonly
The reasons the score came out below 1.0.
Class Method Summary collapse
Instance Method Summary collapse
-
#penalize!(by:, why:)
Reduce
@result. - #initialize(&b) ⇒ LLM::Eval constructor
- #set(**options) ⇒ LLM::Eval
- #configure
- #name(name = UNDEFINED) ⇒ String?
- #description(desc = UNDEFINED) ⇒ String?
- #step(path) ⇒ Array<String>
- #score(&block)
- #result ⇒ Float?
- #setup(&block) ⇒ Object
- #teardown(&block) ⇒ Object
- #intercept(&block) ⇒ Object
- #tracer(&block) ⇒ Object
-
#agent(&block)
Configures the agent.
- #call ⇒ Array<Hash>
-
#eval
Evals @block within self.
Methods included from Run
Constructor Details
#initialize(&b) ⇒ LLM::Eval
65 66 67 68 69 70 71 |
# File 'lib/llm/eval.rb', line 65 def initialize(&b) @steps = [] @block = b @result = 1.0 @final = nil @penalties = [] end |
Instance Attribute Details
#sample ⇒ Integer (readonly)
39 40 41 |
# File 'lib/llm/eval.rb', line 39 def sample @sample end |
#steps ⇒ Array<String> (readonly)
43 44 45 |
# File 'lib/llm/eval.rb', line 43 def steps @steps end |
#model ⇒ String (readonly)
51 52 53 |
# File 'lib/llm/eval.rb', line 51 def model @model end |
#penalties ⇒ Array<Hash> (readonly)
Returns The reasons the score came out below 1.0.
60 61 62 |
# File 'lib/llm/eval.rb', line 60 def penalties @penalties end |
Class Method Details
.from(llm, model, path, sample = 1) ⇒ LLM::Eval
27 28 29 30 31 32 33 34 35 |
# File 'lib/llm/eval.rb', line 27 def self.from(llm, model, path, sample=1) p = File.realpath(path) e = eval File.read(p), TOPLEVEL_BINDING, p, 1 e.instance_variable_set(:@root, File.dirname(p)) e.instance_variable_set(:@llm, llm) e.instance_variable_set(:@model, model) e.instance_variable_set(:@sample, sample) e end |
Instance Method Details
#penalize!(by:, why:)
This method returns an undefined value.
Reduce @result
225 226 227 |
# File 'lib/llm/eval.rb', line 225 def penalize!(by:, why:) @penalties << {by:, why:} end |
#set(**options) ⇒ LLM::Eval
76 77 78 79 |
# File 'lib/llm/eval.rb', line 76 def set(**) .each { |key, value| public_send(key, value) } self end |
#configure
This method returns an undefined value.
83 84 85 |
# File 'lib/llm/eval.rb', line 83 def configure(&) instance_eval(&) end |
#name(name = UNDEFINED) ⇒ String?
90 91 92 93 94 95 96 |
# File 'lib/llm/eval.rb', line 90 def name(name = UNDEFINED) if name == UNDEFINED @name else @name = name end end |
#description(desc = UNDEFINED) ⇒ String?
101 102 103 104 105 106 107 |
# File 'lib/llm/eval.rb', line 101 def description(desc = UNDEFINED) if desc == UNDEFINED @desc else @desc = desc end end |
#step(path) ⇒ Array<String>
112 113 114 115 |
# File 'lib/llm/eval.rb', line 112 def step(path) target = File.join(@root, path) @steps << File.read(target) end |
#score(&block)
This method returns an undefined value.
122 123 124 125 126 127 128 |
# File 'lib/llm/eval.rb', line 122 def score(&block) if block @score = block else @score end end |
#result ⇒ Float?
132 133 134 |
# File 'lib/llm/eval.rb', line 132 def result @final ? @final.clamp(0.0, 1.0) : @final end |
#setup(&block) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/llm/eval.rb', line 139 def setup(&block) if block @setup = block else @setup end end |
#teardown(&block) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/llm/eval.rb', line 150 def teardown(&block) if block @teardown = block else @teardown end end |
#intercept(&block) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/llm/eval.rb', line 161 def intercept(&block) if block @intercept = block else @intercept end end |
#tracer(&block) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/llm/eval.rb', line 172 def tracer(&block) if block @tracer = block else @tracer end end |
#agent(&block)
This method returns an undefined value.
Configures the agent
183 184 185 186 187 188 189 |
# File 'lib/llm/eval.rb', line 183 def agent(&block) if block @agent = block else @agent end end |
#call ⇒ Array<Hash>
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/llm/eval.rb', line 193 def call eval _agent = agent steps.each { _agent.talk(it, model:) } score.call(_agent) penalties.each { @result -= it[:by] } @final = @result if tracer tracer.on_exit run_aggregate end {name:, score: @result} end |
#eval
This method returns an undefined value.
Evals @block within self.
210 211 212 213 214 215 216 217 218 |
# File 'lib/llm/eval.rb', line 210 def eval instance_eval(&@block) if @block instance_eval(&@setup) if @setup @intercept = instance_eval(&@intercept) if @intercept @tracer = instance_eval(&@tracer) if @tracer @agent = @agent.call ensure instance_eval(&@teardown) if @teardown end |