Class: LlmLogs::Batch::Reconciler

Inherits:
Object
  • Object
show all
Defined in:
app/models/llm_logs/batch/reconciler.rb

Overview

Resumes a submitted batch by id, and once terminal, records a trace per request, routes each result to its registered handler, and updates statuses. Idempotent at the request level (succeeded/failed/fell_back requests are skipped on re-run).

Instance Method Summary collapse

Constructor Details

#initialize(batch) ⇒ Reconciler

Returns a new instance of Reconciler.



7
8
9
# File 'app/models/llm_logs/batch/reconciler.rb', line 7

def initialize(batch)
  @batch = batch
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/llm_logs/batch/reconciler.rb', line 11

def call
  rubyllm_batch = RubyLLM.batch(id: @batch.openai_batch_id, provider: LlmLogs.batch_provider)
  status = rubyllm_batch.status

  case status
  when "completed"
    reconcile_completed(rubyllm_batch)
  when "failed", "expired", "cancelled"
    fail_all(status)
  end
  @batch
end