Class: RubyLLM::Evals::ExecuteSampleJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/ruby_llm/evals/execute_sample_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(run_id:, sample_id:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/ruby_llm/evals/execute_sample_job.rb', line 6

def perform(run_id:, sample_id:)
  run = Run.find run_id
  sample = Sample.find sample_id

  prompt_execution = PromptExecution.find_or_create_by(active_job_id: job_id, run:, sample:)
  prompt_execution.update(started_at: Time.current, error_message: nil)

  prompt_execution.execute

  prompt_execution.update ended_at: Time.current

  if run.prompt_executions.count == run.prompt.samples.count
    run.update ended_at: Time.current
  end
rescue StandardError => e
  prompt_execution&.update error_message: e.message
  raise
end