Class: CompletionKit::GenerateRowJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/completion_kit/generate_row_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rate_limit_wait(executions) ⇒ Object



11
12
13
# File 'app/jobs/completion_kit/generate_row_job.rb', line 11

def self.rate_limit_wait(executions)
  30 * executions
end

Instance Method Details

#perform(run_id, response_id) ⇒ Object

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/jobs/completion_kit/generate_row_job.rb', line 37

def perform(run_id, response_id)
  @run_id = run_id
  @response_id = response_id

  response = Response.find(response_id)
  run = response.run
  prompt = run.prompt

  row = parsed_input(response)
  rendered = CsvProcessor.apply_variables(prompt, row)
  client = LlmClient.for_model(prompt.llm_model, ApiConfig.for_model(prompt.llm_model))

  raise ConfigurationError, client.configuration_errors.join(", ") unless client.configured?

  text = client.generate_completion(rendered, model: prompt.llm_model, temperature: run.temperature)

  response.update!(
    status: "succeeded",
    response_text: text,
    error_provider: nil, error_class: nil, error_status: nil, error_message: nil
  )
  run.send(:broadcast_response_update, response)

  if run.judge_configured?
    run.metrics.each do |metric|
      JudgeReviewJob.perform_later(response.id, metric.id)
    end
  end

  enqueue_completion_check
end