Class: LLM::Registry::Model

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Model

Returns a new instance of Model.

Parameters:



23
24
25
# File 'lib/llm/registry/model.rb', line 23

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataLLM::Object (readonly)

Returns The model's metadata.

Returns:



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.

Parameters:

Returns:

  • (Integer, nil)


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

Returns:

  • (Boolean)


131
132
133
# File 'lib/llm/registry/model.rb', line 131

def audio?
  supports?("audio")
end

#context_windowInteger?

Returns the model's context window.

Returns:

  • (Integer, nil)

    Returns the model's context window.



86
87
88
# File 'lib/llm/registry/model.rb', line 86

def context_window
  limit&.context
end

#costLLM::Object

Returns the model's pricing.

Returns:



42
43
44
# File 'lib/llm/registry/model.rb', line 42

def cost
  data.cost
end

#idString

Returns:

  • (String)


29
30
31
# File 'lib/llm/registry/model.rb', line 29

def id
  data.id
end

#image?Boolean

Returns:

  • (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.

Parameters:

  • modality (String)

    One of "text", "image", "audio", "video", "pdf".

Returns:

  • (Boolean)


152
153
154
# File 'lib/llm/registry/model.rb', line 152

def input?(modality)
  modalities&.input&.include?(modality)
end

#input_costFloat?

Returns the input price per million tokens, or nil when unpriced.

Returns:

  • (Float, nil)

    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

#limitLLM::Object

Returns the model's limits (context window, output).

Returns:

  • (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

#modalitiesLLM::Object

Returns the model's input/output modalities.

Returns:

  • (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

#nameString

Returns:

  • (String)


35
36
37
# File 'lib/llm/registry/model.rb', line 35

def name
  data.name || id
end

#open_weights?Boolean

Returns:

  • (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.

Parameters:

  • modality (String)

    One of "text", "image", "audio", "video", "pdf".

Returns:

  • (Boolean)


161
162
163
# File 'lib/llm/registry/model.rb', line 161

def output?(modality)
  modalities&.output&.include?(modality)
end

#output_costFloat?

Returns the output price per million tokens, or nil when unpriced.

Returns:

  • (Float, nil)

    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

Returns:

  • (Boolean)


137
138
139
# File 'lib/llm/registry/model.rb', line 137

def pdf?
  supports?("pdf")
end

#reasoning?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/llm/registry/model.rb', line 98

def reasoning?
  !!data.reasoning
end

#structured_output?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


119
120
121
# File 'lib/llm/registry/model.rb', line 119

def text?
  input?("text") and output?("text")
end

#tool_call?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/llm/registry/model.rb', line 92

def tool_call?
  !!data.tool_call
end

#video?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/llm/registry/model.rb', line 143

def video?
  supports?("video")
end