13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/llm_cost_tracker/pricing/lookup.rb', line 13
def call(provider:, model:)
provider_name = provider.to_s.presence
model_name = model.to_s
cache_key = [provider_name, model_name]
cached = cached_lookup(cache_key)
return cached unless cached.equal?(CACHE_MISS)
provider_model = provider_name ? "#{provider_name}/#{model_name}" : model_name
normalized_model = normalize_model_name(model_name)
current = current_price_tables
match =
explain_table(
table: current.fetch(:pricing_overrides),
source: :pricing_overrides,
provider_model: provider_model,
model_name: model_name,
normalized_model: normalized_model
) ||
explain_table(
table: current.fetch(:file_prices),
source: :prices_file,
provider_model: provider_model,
model_name: model_name,
normalized_model: normalized_model
) ||
explain_table(
table: Registry.builtin_prices,
source: :bundled,
provider_model: provider_model,
model_name: model_name,
normalized_model: normalized_model
)
cache_lookup(cache_key, match)
match
end
|