Class: LlmCostTracker::UsageBreakdown

Inherits:
Data
  • Object
show all
Defined in:
lib/llm_cost_tracker/usage_breakdown.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_read_input_tokensObject (readonly)

Returns the value of attribute cache_read_input_tokens

Returns:

  • (Object)

    the current value of cache_read_input_tokens



4
5
6
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 4

def cache_read_input_tokens
  @cache_read_input_tokens
end

#cache_write_input_tokensObject (readonly)

Returns the value of attribute cache_write_input_tokens

Returns:

  • (Object)

    the current value of cache_write_input_tokens



4
5
6
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 4

def cache_write_input_tokens
  @cache_write_input_tokens
end

#hidden_output_tokensObject (readonly)

Returns the value of attribute hidden_output_tokens

Returns:

  • (Object)

    the current value of hidden_output_tokens



4
5
6
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 4

def hidden_output_tokens
  @hidden_output_tokens
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



4
5
6
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 4

def input_tokens
  @input_tokens
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



4
5
6
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 4

def output_tokens
  @output_tokens
end

Class Method Details

.build(input_tokens:, output_tokens:, cache_read_input_tokens: 0, cache_write_input_tokens: 0, hidden_output_tokens: 0) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 11

def self.build(input_tokens:, output_tokens:, cache_read_input_tokens: 0,
               cache_write_input_tokens: 0, hidden_output_tokens: 0)
  new(
    input_tokens: input_tokens.to_i,
    cache_read_input_tokens: cache_read_input_tokens.to_i,
    cache_write_input_tokens: cache_write_input_tokens.to_i,
    output_tokens: output_tokens.to_i,
    hidden_output_tokens: hidden_output_tokens.to_i
  )
end

Instance Method Details

#to_hObject



26
27
28
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 26

def to_h
  super.merge(total_tokens: total_tokens).compact
end

#total_tokensObject



22
23
24
# File 'lib/llm_cost_tracker/usage_breakdown.rb', line 22

def total_tokens
  input_tokens + cache_read_input_tokens + cache_write_input_tokens + output_tokens
end