Class: LlmCostTracker::LlmApiCall
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- LlmCostTracker::LlmApiCall
- Defined in:
- lib/llm_cost_tracker/llm_api_call.rb
Class Method Summary collapse
- .cost_by_model ⇒ Object
- .cost_by_provider ⇒ Object
- .daily_costs(days: 30) ⇒ Object
-
.total_cost ⇒ Object
Aggregations.
- .total_tokens ⇒ Object
Instance Method Summary collapse
Class Method Details
.cost_by_model ⇒ Object
30 31 32 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 30 def self.cost_by_model group(:model).sum(:total_cost) end |
.cost_by_provider ⇒ Object
34 35 36 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 34 def self.cost_by_provider group(:provider).sum(:total_cost) end |
.daily_costs(days: 30) ⇒ Object
38 39 40 41 42 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 38 def self.daily_costs(days: 30) where(tracked_at: days.days.ago..) .group("DATE(tracked_at)") .sum(:total_cost) end |
.total_cost ⇒ Object
Aggregations
22 23 24 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 22 def self.total_cost sum(:total_cost).to_f end |
.total_tokens ⇒ Object
26 27 28 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 26 def self.total_tokens sum(:total_tokens).to_i end |
Instance Method Details
#feature ⇒ Object
50 51 52 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 50 def feature ["feature"] end |
#parsed_tags ⇒ Object
44 45 46 47 48 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 44 def JSON.parse( || "{}") rescue JSON::ParserError {} end |
#user_id ⇒ Object
54 55 56 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 54 def user_id ["user_id"] end |