Module: LlmCostTracker::Pricing::Lookup
- Defined in:
- lib/llm_cost_tracker/pricing/lookup.rb
Defined Under Namespace
Classes: Match
Constant Summary collapse
- MUTEX =
Monitor.new
- CACHE_MISS =
Object.new.freeze
- NO_MATCH =
Object.new.freeze
- MAX_LOOKUP_CACHE_ENTRIES =
512
Class Method Summary collapse
Class Method Details
.call(provider:, model:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/llm_cost_tracker/pricing/lookup.rb', line 15 def call(provider:, model:) provider_name = provider.to_s model_name = model.to_s generation = LlmCostTracker.configuration_generation cache_key = [generation, provider_name, model_name] cached = cached_lookup(cache_key) return cached unless cached.equal?(CACHE_MISS) provider_model = provider_name.empty? ? model_name : "#{provider_name}/#{model_name}" normalized_model = normalize_model_name(model_name) current = current_price_tables(generation) match = explain_table(current.fetch(:pricing_overrides), :pricing_overrides, provider_model, model_name, normalized_model) || explain_table(current.fetch(:file_prices), :prices_file, provider_model, model_name, normalized_model) || explain_table(Pricing::PRICES, :bundled, provider_model, model_name, normalized_model) cache_lookup(cache_key, match) match end |