Class: LlmCostTracker::Dashboard::TagBreakdown

Inherits:
Object
  • Object
show all
Defined in:
app/services/llm_cost_tracker/dashboard/tag_breakdown.rb

Constant Summary collapse

DEFAULT_LIMIT =
100

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, key:, limit:) ⇒ TagBreakdown

Returns a new instance of TagBreakdown.



31
32
33
34
35
36
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 31

def initialize(scope:, key:, limit:)
  @scope = scope
  @key = LlmCostTracker::TagKey.validate!(key, error_class: LlmCostTracker::InvalidFilterError)
  @limit = normalized_limit(limit)
  @connection = LlmCostTracker::LlmApiCall.connection
end

Class Method Details

.call(key:, scope: LlmCostTracker::LlmApiCall.all, limit: DEFAULT_LIMIT) ⇒ Object



26
27
28
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 26

def call(key:, scope: LlmCostTracker::LlmApiCall.all, limit: DEFAULT_LIMIT)
  new(scope: scope, key: key, limit: limit).result
end

Instance Method Details

#resultObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 38

def result
  counts = summary_counts

  TagBreakdownResult.new(
    rows: rows,
    total_calls: counts.fetch(:total_calls),
    tagged_calls: counts.fetch(:tagged_calls),
    distinct_values: counts.fetch(:distinct_values),
    limit: limit
  )
end