18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/llm_cost_tracker/event_metadata.rb', line 18
def usage_data(input_tokens, output_tokens, metadata)
metadata = metadata.to_h.symbolize_keys
cache_read = first_integer(metadata, :cache_read_input_tokens, :cache_read_tokens)
cache_creation = first_integer(metadata, :cache_creation_input_tokens, :cache_creation_tokens)
{
input_tokens: input_tokens.to_i,
output_tokens: output_tokens.to_i,
cached_input_tokens: metadata[:cached_input_tokens].to_i,
cache_read_input_tokens: cache_read,
cache_creation_input_tokens: cache_creation,
total_tokens: input_tokens.to_i + output_tokens.to_i + cache_read + cache_creation
}
end
|