Class: Riffer::Config::Pricing
- Inherits:
-
Object
- Object
- Riffer::Config::Pricing
- Defined in:
- lib/riffer/config.rb
Overview
Consumer-configured token pricing, keyed by provider/model id. Riffer ships no price table, so an unconfigured model carries no cost.
Defined Under Namespace
Classes: Rates
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns true when no rates are registered.
-
#initialize ⇒ Pricing
constructor
– : () -> void.
-
#rates_for(model) ⇒ Object
Returns the rates registered for a
provider/modelid. -
#set(models, input:, output:, cache_read: nil, cache_write: nil) ⇒ Object
Registers per-million-token rates for a
provider/modelid/s.
Constructor Details
#initialize ⇒ Pricing
– : () -> void
199 200 201 |
# File 'lib/riffer/config.rb', line 199 def initialize @rates = {} end |
Instance Method Details
#empty? ⇒ Boolean
Returns true when no rates are registered. – : () -> bool
231 232 233 |
# File 'lib/riffer/config.rb', line 231 def empty? @rates.empty? end |
#rates_for(model) ⇒ Object
Returns the rates registered for a provider/model id. – : (String) -> Riffer::Config::Pricing::Rates?
224 225 226 |
# File 'lib/riffer/config.rb', line 224 def rates_for(model) @rates[model] end |
#set(models, input:, output:, cache_read: nil, cache_write: nil) ⇒ Object
Registers per-million-token rates for a provider/model id/s. Raises Riffer::ArgumentError on a malformed id or a negative/non-numeric rate. – : ((String | Array), input: Numeric, output: Numeric, ?cache_read: Numeric?, ?cache_write: Numeric?) -> void
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/riffer/config.rb', line 207 def set(models, input:, output:, cache_read: nil, cache_write: nil) ids = models.is_a?(Array) ? models : [models] raise Riffer::ArgumentError, "at least one model id is required" if ids.empty? ids.each { |id| validate_model!(id) } rates = Rates.new( input: coerce_rate(input, "input"), output: coerce_rate(output, "output"), cache_read: coerce_optional_rate(cache_read, "cache_read"), cache_write: coerce_optional_rate(cache_write, "cache_write") ) ids.each { |id| @rates[id] = rates } end |