Module: LlmCostTracker::Usage::Catalog

Defined in:
lib/llm_cost_tracker/usage/catalog.rb

Constant Summary collapse

DEFINITIONS_PATH =
File.expand_path("dimensions.yml", __dir__)
DEFAULT_RATE_BASIS_BY_UNIT =
{
  "token" => "per_million_tokens",
  "character" => "per_million_characters",
  "request" => "per_request",
  "session" => "per_session",
  "hour" => "per_hour",
  "minute" => "per_minute"
}.freeze

Class Method Summary collapse

Class Method Details

.allObject



25
26
27
# File 'lib/llm_cost_tracker/usage/catalog.rb', line 25

def all
  @all ||= load_definitions.freeze
end

.find_by(kind:, direction:, modality:, cache_state:, unit:) ⇒ Object



33
34
35
# File 'lib/llm_cost_tracker/usage/catalog.rb', line 33

def find_by(kind:, direction:, modality:, cache_state:, unit:)
  by_attributes[[kind, direction, modality, cache_state, unit]]
end

.token_pricedObject



29
30
31
# File 'lib/llm_cost_tracker/usage/catalog.rb', line 29

def token_priced
  @token_priced ||= all.select(&:token_key).freeze
end

.token_priced_for(kind:, direction:, cache_state:) ⇒ Object



37
38
39
40
41
# File 'lib/llm_cost_tracker/usage/catalog.rb', line 37

def token_priced_for(kind:, direction:, cache_state:)
  token_priced.find do |dimension|
    dimension.kind == kind && dimension.direction == direction && dimension.cache_state == cache_state
  end
end