Class: LlmCostTracker::PriceSync::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/price_sync/validator.rb

Defined Under Namespace

Classes: Issue, Result

Constant Summary collapse

MAX_INPUT_PER_MILLION =
100.0
MAX_OUTPUT_PER_MILLION =
500.0
MAX_RELATIVE_CHANGE =
3.0

Instance Method Summary collapse

Instance Method Details

#validate_batch(merged_prices, existing_registry:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/llm_cost_tracker/price_sync/validator.rb', line 13

def validate_batch(merged_prices, existing_registry:)
  merged_prices.each_with_object(Result.new(accepted: {}, rejected: [], flagged: [])) do |(model, price), result|
    old_price = normalize_entry(existing_registry[model])
    status, reason = validate(new_price: price, old_price: old_price)

    case status
    when :rejected
      result.rejected << Issue.new(model: model, reason: reason, old_price: old_price, new_price: price)
    when :flagged
      result.flagged << Issue.new(model: model, reason: reason, old_price: old_price, new_price: price)
      result.accepted[model] = price
    else
      result.accepted[model] = price
    end
  end
end