Module: LlmCostTracker::Pricing::Matcher

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

Defined Under Namespace

Classes: Match

Class Method Summary collapse

Class Method Details

.lookup(provider:, model:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/llm_cost_tracker/pricing/matcher.rb', line 16

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

  sources = Registry.sources
  reset_cache(sources) unless @cache_sources.equal?(sources)
  key = [provider_name, model_name].freeze
  return @cache[key] if @cache.key?(key)

  @cache.clear if @cache.size >= CACHE_LIMIT
  @cache[key] = lookup_match(sources, provider_name, model_name)
end