Class: LLM::Registry
- Inherits:
-
Object
- Object
- LLM::Registry
- Defined in:
- lib/llm/registry.rb,
lib/llm/registry/model.rb
Overview
The LLM::Registry class provides a small API over
provider model data. It exposes model metadata such as pricing,
capabilities, modalities, and limits from the registry files
stored under data/. The data is provided by https://models.dev
and shipped with llm.rb.
Defined Under Namespace
Classes: Model
Class Method Summary collapse
Instance Method Summary collapse
-
#cost(model:) ⇒ LLM::Object
Returns model costs.
- #env ⇒ Array<String>
- #initialize(blob) ⇒ LLM::Registry constructor
-
#keys ⇒ Array<String>
Returns the model keys (names) in the registry.
-
#limit(model:) ⇒ LLM::Object
Returns model limits such as the context window size.
-
#modalities(model:) ⇒ LLM::Object
Returns model modalities.
-
#models ⇒ Array<LLM::Registry::Model>
Returns all models as Model objects.
Constructor Details
#initialize(blob) ⇒ LLM::Registry
32 33 34 35 |
# File 'lib/llm/registry.rb', line 32 def initialize(blob) @registry = LLM::Object.from(blob) @models = @registry.models end |
Class Method Details
.for(name) ⇒ LLM::Registry
19 20 21 22 23 24 25 26 |
# File 'lib/llm/registry.rb', line 19 def self.for(name) path = File.join @root, "data", "#{name}.json" if File.file?(path) new LLM.json.load(File.binread(path)) else raise LLM::NoSuchRegistryError, "no registry found for #{name}" end end |
Instance Method Details
#cost(model:) ⇒ LLM::Object
Returns model costs
60 61 62 |
# File 'lib/llm/registry.rb', line 60 def cost(model:) find(model:).cost end |
#env ⇒ Array<String>
53 54 55 |
# File 'lib/llm/registry.rb', line 53 def env @registry.env end |
#keys ⇒ Array<String>
Returns the model keys (names) in the registry.
40 41 42 |
# File 'lib/llm/registry.rb', line 40 def keys @models.keys end |
#limit(model:) ⇒ LLM::Object
Returns model limits such as the context window size
74 75 76 |
# File 'lib/llm/registry.rb', line 74 def limit(model:) find(model:).limit end |
#modalities(model:) ⇒ LLM::Object
Returns model modalities
67 68 69 |
# File 'lib/llm/registry.rb', line 67 def modalities(model:) find(model:).modalities end |
#models ⇒ Array<LLM::Registry::Model>
Returns all models as Model objects.
47 48 49 |
# File 'lib/llm/registry.rb', line 47 def models @models.map { |id, data| Model.new(data.merge(id:)) } end |