7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# 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 model_class.latency_column?
attributes[:stream] = event.stream if model_class.stream_column?
attributes[:usage_source] = event.usage_source if model_class.usage_source_column?
model_class.create!(attributes)
end
|