Class: LLM::Registry::Model
- Inherits:
-
Object
- Object
- LLM::Registry::Model
- Includes:
- Comparable
- Defined in:
- lib/llm/registry/model.rb
Overview
A single model from the registry, wrapping its metadata (pricing, limits, capabilities, and modalities).
Models are Comparable by price: input cost first, then
output cost, so models.sort orders them from cheapest to
most expensive.
Instance Attribute Summary collapse
-
#data ⇒ LLM::Object
readonly
The model's metadata.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compares models by price: input cost first, then output cost.
- #audio? ⇒ Boolean
-
#context_window ⇒ Integer?
Returns the model's context window.
-
#cost ⇒ LLM::Object
Returns the model's pricing.
- #id ⇒ String
- #image? ⇒ Boolean
-
#initialize(data) ⇒ Model
constructor
A new instance of Model.
-
#input?(modality) ⇒ Boolean
Returns whether the model reads a modality as input.
-
#input_cost ⇒ Float?
Returns the input price per million tokens, or nil when unpriced.
-
#limit ⇒ LLM::Object
Returns the model's limits (context window, output).
-
#modalities ⇒ LLM::Object
Returns the model's input/output modalities.
- #name ⇒ String
- #open_weights? ⇒ Boolean
-
#output?(modality) ⇒ Boolean
Returns whether the model produces a modality as output.
-
#output_cost ⇒ Float?
Returns the output price per million tokens, or nil when unpriced.
- #pdf? ⇒ Boolean
- #reasoning? ⇒ Boolean
- #structured_output? ⇒ Boolean
-
#text? ⇒ Boolean
Returns whether the model is probably a text LLM: it reads and writes text.
- #tool_call? ⇒ Boolean
- #video? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Model
Returns a new instance of Model.
23 24 25 |
# File 'lib/llm/registry/model.rb', line 23 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ LLM::Object (readonly)
Returns The model's metadata.
18 19 20 |
# File 'lib/llm/registry/model.rb', line 18 def data @data end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compares models by price: input cost first, then output cost. Models without a price sort as the most expensive.
65 66 67 |
# File 'lib/llm/registry/model.rb', line 65 def <=>(other) [price(input_cost), price(output_cost)] <=> [price(other.input_cost), price(other.output_cost)] end |
#audio? ⇒ Boolean
131 132 133 |
# File 'lib/llm/registry/model.rb', line 131 def audio? supports?("audio") end |
#context_window ⇒ Integer?
Returns the model's context window.
86 87 88 |
# File 'lib/llm/registry/model.rb', line 86 def context_window limit&.context end |
#cost ⇒ LLM::Object
Returns the model's pricing.
42 43 44 |
# File 'lib/llm/registry/model.rb', line 42 def cost data.cost end |
#id ⇒ String
29 30 31 |
# File 'lib/llm/registry/model.rb', line 29 def id data.id end |
#image? ⇒ Boolean
125 126 127 |
# File 'lib/llm/registry/model.rb', line 125 def image? supports?("image") end |
#input?(modality) ⇒ Boolean
Returns whether the model reads a modality as input.
152 153 154 |
# File 'lib/llm/registry/model.rb', line 152 def input?(modality) modalities&.input&.include?(modality) end |
#input_cost ⇒ Float?
Returns the input price per million tokens, or nil when unpriced.
49 50 51 |
# File 'lib/llm/registry/model.rb', line 49 def input_cost cost&.input end |
#limit ⇒ LLM::Object
Returns the model's limits (context window, output).
72 73 74 |
# File 'lib/llm/registry/model.rb', line 72 def limit data.limit end |
#modalities ⇒ LLM::Object
Returns the model's input/output modalities.
79 80 81 |
# File 'lib/llm/registry/model.rb', line 79 def modalities data.modalities end |
#name ⇒ String
35 36 37 |
# File 'lib/llm/registry/model.rb', line 35 def name data.name || id end |
#open_weights? ⇒ Boolean
110 111 112 |
# File 'lib/llm/registry/model.rb', line 110 def open_weights? !!data.open_weights end |
#output?(modality) ⇒ Boolean
Returns whether the model produces a modality as output.
161 162 163 |
# File 'lib/llm/registry/model.rb', line 161 def output?(modality) modalities&.output&.include?(modality) end |
#output_cost ⇒ Float?
Returns the output price per million tokens, or nil when unpriced.
56 57 58 |
# File 'lib/llm/registry/model.rb', line 56 def output_cost cost&.output end |
#pdf? ⇒ Boolean
137 138 139 |
# File 'lib/llm/registry/model.rb', line 137 def pdf? supports?("pdf") end |
#reasoning? ⇒ Boolean
98 99 100 |
# File 'lib/llm/registry/model.rb', line 98 def reasoning? !!data.reasoning end |
#structured_output? ⇒ Boolean
104 105 106 |
# File 'lib/llm/registry/model.rb', line 104 def structured_output? !!data.structured_output end |
#text? ⇒ Boolean
Returns whether the model is probably a text LLM: it reads and writes text. A generation model that only produces audio or images reports false.
119 120 121 |
# File 'lib/llm/registry/model.rb', line 119 def text? input?("text") and output?("text") end |
#tool_call? ⇒ Boolean
92 93 94 |
# File 'lib/llm/registry/model.rb', line 92 def tool_call? !!data.tool_call end |
#video? ⇒ Boolean
143 144 145 |
# File 'lib/llm/registry/model.rb', line 143 def video? supports?("video") end |