7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/llm_cost_tracker/storage/active_record_store.rb', line 7
def save(event)
tags = stringify_tags(event.tags || {})
attributes = {
provider: event.provider,
model: event.model,
input_tokens: event.input_tokens,
output_tokens: event.output_tokens,
total_tokens: event.total_tokens,
input_cost: event.cost&.input_cost,
output_cost: event.cost&.output_cost,
total_cost: event.cost&.total_cost,
tags: tags_for_storage(tags),
tracked_at: event.tracked_at
}
attributes[:latency_ms] = event.latency_ms if LlmCostTracker::LlmApiCall.latency_column?
attributes[:stream] = event.stream if LlmCostTracker::LlmApiCall.stream_column?
attributes[:usage_source] = event.usage_source if LlmCostTracker::LlmApiCall.usage_source_column?
if LlmCostTracker::LlmApiCall.provider_response_id_column?
attributes[:provider_response_id] = event.provider_response_id
end
LlmCostTracker::LlmApiCall.create!(attributes)
end
|