Class: LlmLogs::Batch
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LlmLogs::Batch
- Defined in:
- app/models/llm_logs/batch.rb,
app/jobs/llm_logs/batch/poll_job.rb,
app/jobs/llm_logs/batch/flush_job.rb,
app/models/llm_logs/batch/submitter.rb,
app/models/llm_logs/batch/reconciler.rb,
app/models/llm_logs/batch/schema_format.rb,
app/models/llm_logs/batch/trace_recorder.rb,
app/models/llm_logs/batch/handler_registry.rb
Defined Under Namespace
Modules: HandlerRegistry, SchemaFormat, TraceRecorder Classes: FlushJob, PollJob, Reconciler, Submitter
Class Method Summary collapse
- .batchable?(model) ⇒ Boolean
- .enqueue(purpose:, model:, input:, instructions:, schema:, routing:, temperature: nil) ⇒ Object
-
.servable_by_batch_provider?(model) ⇒ Boolean
The batch path submits via RubyLLM.batch(provider: batch_provider).
- .submit_pending(purpose:, model:, metadata: {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.batchable?(model) ⇒ Boolean
45 46 47 48 49 50 |
# File 'app/models/llm_logs/batch.rb', line 45 def self.batchable?(model) return false unless LlmLogs.batch_enabled? return false unless defined?(RubyLLM::Providers::OpenAIResponses) servable_by_batch_provider?(model) end |
.enqueue(purpose:, model:, input:, instructions:, schema:, routing:, temperature: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/llm_logs/batch.rb', line 21 def self.enqueue(purpose:, model:, input:, instructions:, schema:, routing:, temperature: nil) BatchRequest.create!( purpose: purpose, model: model, status: :pending, custom_id: "req_#{SecureRandom.hex(8)}", routing: routing, payload: { "input" => input, "instructions" => instructions, "schema" => schema, "temperature" => temperature }.compact ) end |
.servable_by_batch_provider?(model) ⇒ Boolean
The batch path submits via RubyLLM.batch(provider: batch_provider). A model is only batchable if that provider can actually serve it -- i.e. the model resolves under batch_provider. Models that belong to a different provider (e.g. Bedrock / Anthropic) don't resolve there, so they return false and the caller runs them synchronously instead of enqueueing work that would fail at submit time.
57 58 59 60 61 62 63 64 |
# File 'app/models/llm_logs/batch.rb', line 57 def self.servable_by_batch_provider?(model) RubyLLM::Models.resolve( model, provider: LlmLogs.batch_provider, assume_exists: false, config: RubyLLM.config ) true rescue RubyLLM::ModelNotFoundError false end |
Instance Method Details
#reconcile! ⇒ Object
41 42 43 |
# File 'app/models/llm_logs/batch.rb', line 41 def reconcile! Reconciler.new(self).call end |