Class: Tracebook::PricingRule
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Tracebook::PricingRule
- Defined in:
- app/models/tracebook/pricing_rule.rb
Overview
Pricing rule for calculating LLM interaction costs.
Defines cost per 1000 tokens for a provider/model pattern. Supports glob patterns for matching multiple models and date-based effective periods.
Fields
provider- Provider name (e.g., "openai", "anthropic")model_glob- Glob pattern for matching models (e.g., "gpt-4o*", "claude-3-5-*")input_per_1k- Cost per 1000 input tokensoutput_per_1k- Cost per 1000 output tokenscurrency- Currency code (e.g., "USD")effective_from- Date this pricing takes effecteffective_to- Optional end date for this pricing
Instance Method Summary collapse
-
#active_on?(date) ⇒ Boolean
Returns true if this rule is active on the given date.
-
#matches_model?(model) ⇒ Boolean
Returns true if this rule's glob pattern matches the given model.
Instance Method Details
#active_on?(date) ⇒ Boolean
Returns true if this rule is active on the given date.
62 63 64 |
# File 'app/models/tracebook/pricing_rule.rb', line 62 def active_on?(date) date >= effective_from && (effective_to.nil? || date < effective_to) end |
#matches_model?(model) ⇒ Boolean
Returns true if this rule's glob pattern matches the given model.
Uses case-insensitive file glob matching.
78 79 80 |
# File 'app/models/tracebook/pricing_rule.rb', line 78 def matches_model?(model) File.fnmatch?(model_glob, model, File::FNM_CASEFOLD) end |