14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/llm_cost_tracker/integrations/openai/batch_capture.rb', line 14
def maybe_capture(batch, resource:)
return unless Openai.active?
return unless batch.status.to_s == "completed"
return unless batch.output_file_id && batch.id
return if captured?(batch.id)
client = resource.instance_variable_get(:@client)
host = Openai.client_host_for(resource)
Openai.record_safely do
io = client.files.content(batch.output_file_id)
capture_jsonl(io.respond_to?(:read) ? io.read : io.to_s, host: host)
mark_captured(batch.id)
end
end
|