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
28 29 30 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 28 def self.cost_by_model group(:model).sum(:total_cost) end |
.cost_by_provider ⇒ Object
32 33 34 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 32 def self.cost_by_provider group(:provider).sum(:total_cost) end |
.daily_costs(days: 30) ⇒ Object
36 37 38 39 40 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 36 def self.daily_costs(days: 30) where(tracked_at: days.days.ago..) .group("DATE(tracked_at)") .sum(:total_cost) end |
.total_cost ⇒ Object
Aggregations
20 21 22 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 20 def self.total_cost sum(:total_cost).to_f end |
.total_tokens ⇒ Object
24 25 26 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 24 def self.total_tokens sum(:total_tokens).to_i end |
Instance Method Details
#feature ⇒ Object
48 49 50 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 48 def feature ["feature"] end |
#parsed_tags ⇒ Object
42 43 44 45 46 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 42 def JSON.parse( || "{}") rescue JSON::ParserError {} end |
#user_id ⇒ Object
52 53 54 |
# File 'lib/llm_cost_tracker/llm_api_call.rb', line 52 def user_id ["user_id"] end |