Class: Mistri::Models::Model
- Inherits:
-
Data
- Object
- Data
- Mistri::Models::Model
- Defined in:
- lib/mistri/models.rb
Overview
thinking is how the model accepts a reasoning request: :adaptive (the model decides), :budget (a token budget), or :effort. It is what keeps a provider from sending an unsupported thinking shape that 400s.
context_window is the provider's published context or input limit. Anthropic and OpenAI share it with the next output; Gemini publishes a separate inputTokenLimit and outputTokenLimit.
Pricing is selected per request from its prompt size. Rates are paid standard direct-API list prices. cache_write is the provider's baseline write rate; Usage prices a reported longer-retention slice separately.
Instance Attribute Summary collapse
-
#context_window ⇒ Object
readonly
Returns the value of attribute context_window.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#max_output ⇒ Object
readonly
Returns the value of attribute max_output.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #_dump(_level) ⇒ Object
- #hash ⇒ Object
-
#initialize(id:, provider:, max_output:, context_window:, thinking:, pricing: []) ⇒ Model
constructor
A new instance of Model.
- #priced? ⇒ Boolean
- #rates(usage: nil, at: Time.now) ⇒ Object
- #with(**changes) ⇒ Object
Constructor Details
#initialize(id:, provider:, max_output:, context_window:, thinking:, pricing: []) ⇒ Model
Returns a new instance of Model.
43 44 45 46 |
# File 'lib/mistri/models.rb', line 43 def initialize(id:, provider:, max_output:, context_window:, thinking:, pricing: []) @pricing = pricing.sort_by(&:effective_at).freeze super(id:, provider:, max_output:, context_window:, thinking:) end |
Instance Attribute Details
#context_window ⇒ Object (readonly)
Returns the value of attribute context_window
42 43 44 |
# File 'lib/mistri/models.rb', line 42 def context_window @context_window end |
#id ⇒ Object (readonly)
Returns the value of attribute id
42 43 44 |
# File 'lib/mistri/models.rb', line 42 def id @id end |
#max_output ⇒ Object (readonly)
Returns the value of attribute max_output
42 43 44 |
# File 'lib/mistri/models.rb', line 42 def max_output @max_output end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider
42 43 44 |
# File 'lib/mistri/models.rb', line 42 def provider @provider end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking
42 43 44 |
# File 'lib/mistri/models.rb', line 42 def thinking @thinking end |
Class Method Details
._load(payload) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mistri/models.rb', line 73 def self._load(payload) attributes = JSON.parse(payload, symbolize_names: true) serialized = attributes.delete(:pricing) pricing = serialized.map do |entry| card = RateCard.new(rates: entry[:rates], above: entry[:above], higher: entry[:higher]) Schedule.new(effective_at: Time.at(entry[:effective_at]).utc, card:) end attributes[:provider] = attributes[:provider].to_sym attributes[:thinking] = attributes[:thinking].to_sym new(**attributes, pricing:) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
59 |
# File 'lib/mistri/models.rb', line 59 def ==(other) = super && pricing == other.send(:pricing) |
#_dump(_level) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/mistri/models.rb', line 65 def _dump(_level) serialized = pricing.map do |entry| { effective_at: entry.effective_at.to_i, rates: entry.card.rates, above: entry.card.above, higher: entry.card.higher } end JSON.generate(to_h.merge(pricing: serialized)) end |
#hash ⇒ Object
63 |
# File 'lib/mistri/models.rb', line 63 def hash = [super, pricing].hash |
#priced? ⇒ Boolean
52 |
# File 'lib/mistri/models.rb', line 52 def priced? = !pricing.empty? |
#rates(usage: nil, at: Time.now) ⇒ Object
48 49 50 |
# File 'lib/mistri/models.rb', line 48 def rates(usage: nil, at: Time.now) pricing.reverse_each.find { |entry| entry.effective_at <= at }&.card&.rates_for(usage) end |
#with(**changes) ⇒ Object
54 55 56 57 |
# File 'lib/mistri/models.rb', line 54 def with(**changes) updated_pricing = changes.delete(:pricing) { pricing } self.class.new(**to_h, **changes, pricing: updated_pricing) end |