Module: LlmCostTracker::Pricing::Lookup

Defined in:
lib/llm_cost_tracker/pricing/lookup.rb

Defined Under Namespace

Classes: Match

Constant Summary collapse

MUTEX =
Mutex.new
CACHE_MISS =
Object.new.freeze
NO_MATCH =
Object.new.freeze

Class Method Summary collapse

Class Method Details

.call(provider:, model:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/llm_cost_tracker/pricing/lookup.rb', line 12

def call(provider:, model:)
  provider_name = provider.to_s.presence
  model_name = model.to_s
  return nil if model_name.empty?

  cache_key = [provider_name, model_name]
  cached = cached_lookup(cache_key)
  return cached unless cached.equal?(CACHE_MISS)

  match = lookup_match(provider_name: provider_name, model_name: model_name)
  cache_lookup(cache_key, match)
  match
end

.reset!Object



26
27
28
29
30
31
32
# File 'lib/llm_cost_tracker/pricing/lookup.rb', line 26

def reset!
  MUTEX.synchronize do
    @prices_cache = nil
    @lookup_cache = nil
    @sorted_price_keys_cache = nil
  end
end