Class: LlmCostTracker::LlmApiCall
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- LlmCostTracker::LlmApiCall
show all
- Extended by:
- TagsColumn
- Includes:
- TagAccessors
- Defined in:
- lib/llm_cost_tracker/llm_api_call.rb
Class Method Summary
collapse
Methods included from TagsColumn
latency_column?, tags_json_column?
#feature, #parsed_tags, #user_id
Class Method Details
.average_latency_ms ⇒ Object
64
65
66
67
68
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 64
def self.average_latency_ms
return nil unless latency_column?
average(:latency_ms)&.to_f
end
|
.by_tag(key, value) ⇒ Object
39
40
41
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 39
def self.by_tag(key, value)
by_tags(key => value)
end
|
43
44
45
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 43
def self.by_tags(tags)
TagQuery.apply(self, tags)
end
|
.cost_by_model ⇒ Object
56
57
58
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 56
def self.cost_by_model
group(:model).sum(:total_cost)
end
|
.cost_by_provider ⇒ Object
60
61
62
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 60
def self.cost_by_provider
group(:provider).sum(:total_cost)
end
|
.daily_costs(days: 30) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 82
def self.daily_costs(days: 30)
where(tracked_at: days.days.ago..)
.group("DATE(tracked_at)")
.sum(:total_cost)
.transform_keys(&:to_s)
end
|
.latency_by_model ⇒ Object
70
71
72
73
74
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 70
def self.latency_by_model
return {} unless latency_column?
group(:model).average(:latency_ms).transform_values(&:to_f)
end
|
.latency_by_provider ⇒ Object
76
77
78
79
80
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 76
def self.latency_by_provider
return {} unless latency_column?
group(:provider).average(:latency_ms).transform_values(&:to_f)
end
|
.total_cost ⇒ Object
48
49
50
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 48
def self.total_cost
sum(:total_cost).to_f
end
|
.total_tokens ⇒ Object
52
53
54
|
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 52
def self.total_tokens
sum(:total_tokens).to_i
end
|