Module: LlmCostTracker::TokenUsageHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/llm_cost_tracker/token_usage_helper.rb

Constant Summary collapse

COMPONENT_LABELS =
{
  input_tokens: "Input",
  cache_read_input_tokens: "Cache read",
  cache_write_input_tokens: "Cache write",
  cache_write_1h_input_tokens: "1h cache write",
  output_tokens: "Output",
  hidden_output_tokens: "Hidden output"
}.freeze
QUALITY_LABELS =
COMPONENT_LABELS.merge(
  input_tokens: "Regular input",
  cache_read_input_tokens: "Cache read input",
  cache_write_input_tokens: "Cache write input",
  cache_write_1h_input_tokens: "1h cache write input"
).freeze
STACK_CLASSES =
{
  input_tokens: "lct-stack-fill-input",
  cache_read_input_tokens: "lct-stack-fill-cache-read",
  cache_write_input_tokens: "lct-stack-fill-cache-write",
  cache_write_1h_input_tokens: "lct-stack-fill-cache-write-1h",
  output_tokens: "lct-stack-fill-output"
}.freeze

Instance Method Summary collapse

Instance Method Details

#token_usage_quality_label(token_key) ⇒ Object



33
34
35
# File 'app/helpers/llm_cost_tracker/token_usage_helper.rb', line 33

def token_usage_quality_label(token_key)
  QUALITY_LABELS.fetch(token_key.to_sym)
end

#token_usage_stack_componentsObject



27
28
29
30
31
# File 'app/helpers/llm_cost_tracker/token_usage_helper.rb', line 27

def token_usage_stack_components
  token_usage_display_components(labels: COMPONENT_LABELS).select do |component|
    component.fetch(:cost_key)
  end
end