Class: LlmCostTracker::ReportData
- Inherits:
-
Data
- Object
- Data
- LlmCostTracker::ReportData
- Defined in:
- lib/llm_cost_tracker/report_data.rb,
lib/llm_cost_tracker/report_data.rb
Constant Summary collapse
- DEFAULT_DAYS =
30- TOP_LIMIT =
5
Instance Attribute Summary collapse
-
#average_latency_ms ⇒ Object
readonly
Returns the value of attribute average_latency_ms.
-
#cost_by_model ⇒ Object
readonly
Returns the value of attribute cost_by_model.
-
#cost_by_provider ⇒ Object
readonly
Returns the value of attribute cost_by_provider.
-
#cost_by_tags ⇒ Object
readonly
Returns the value of attribute cost_by_tags.
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#from_time ⇒ Object
readonly
Returns the value of attribute from_time.
-
#requests_count ⇒ Object
readonly
Returns the value of attribute requests_count.
-
#to_time ⇒ Object
readonly
Returns the value of attribute to_time.
-
#top_calls ⇒ Object
readonly
Returns the value of attribute top_calls.
-
#total_cost ⇒ Object
readonly
Returns the value of attribute total_cost.
-
#unknown_pricing_count ⇒ Object
readonly
Returns the value of attribute unknown_pricing_count.
Class Method Summary collapse
Instance Attribute Details
#average_latency_ms ⇒ Object (readonly)
Returns the value of attribute average_latency_ms
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def average_latency_ms @average_latency_ms end |
#cost_by_model ⇒ Object (readonly)
Returns the value of attribute cost_by_model
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def cost_by_model @cost_by_model end |
#cost_by_provider ⇒ Object (readonly)
Returns the value of attribute cost_by_provider
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def cost_by_provider @cost_by_provider end |
#cost_by_tags ⇒ Object (readonly)
Returns the value of attribute cost_by_tags
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def @cost_by_tags end |
#days ⇒ Object (readonly)
Returns the value of attribute days
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def days @days end |
#from_time ⇒ Object (readonly)
Returns the value of attribute from_time
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def from_time @from_time end |
#requests_count ⇒ Object (readonly)
Returns the value of attribute requests_count
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def requests_count @requests_count end |
#to_time ⇒ Object (readonly)
Returns the value of attribute to_time
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def to_time @to_time end |
#top_calls ⇒ Object (readonly)
Returns the value of attribute top_calls
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def top_calls @top_calls end |
#total_cost ⇒ Object (readonly)
Returns the value of attribute total_cost
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def total_cost @total_cost end |
#unknown_pricing_count ⇒ Object (readonly)
Returns the value of attribute unknown_pricing_count
8 9 10 |
# File 'lib/llm_cost_tracker/report_data.rb', line 8 def unknown_pricing_count @unknown_pricing_count end |
Class Method Details
.build(days: DEFAULT_DAYS, now: Time.now.utc, tag_breakdowns: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/llm_cost_tracker/report_data.rb', line 26 def self.build(days: DEFAULT_DAYS, now: Time.now.utc, tag_breakdowns: nil) require_relative "llm_api_call" unless defined?(LlmCostTracker::LlmApiCall) days = normalized_days(days) from = now - days.days scope = LlmApiCall.where(tracked_at: from..now) tag_breakdowns ||= LlmCostTracker.configuration.report_tag_breakdowns || [] new( days: days, from_time: from, to_time: now, total_cost: scope.sum(:total_cost).to_f, requests_count: scope.count, average_latency_ms: average_latency_ms(scope), unknown_pricing_count: scope.where(total_cost: nil).count, cost_by_provider: cost_by(scope, :provider), cost_by_model: cost_by(scope, :model), cost_by_tags: (scope, tag_breakdowns), top_calls: top_calls(scope) ) end |