Class: LLM::Registry

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

Constructor Details

#initialize(blob) ⇒ LLM::Registry

Parameters:

  • blob (Hash)

    A model 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

Parameters:

  • name (Symbol)

    A provider name

Returns:

Raises:



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

Returns:



60
61
62
# File 'lib/llm/registry.rb', line 60

def cost(model:)
  find(model:).cost
end

#envArray<String>

Returns:

  • (Array<String>)


53
54
55
# File 'lib/llm/registry.rb', line 53

def env
  @registry.env
end

#keysArray<String>

Returns the model keys (names) in the registry.

Returns:

  • (Array<String>)


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

Returns:

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

Returns:



67
68
69
# File 'lib/llm/registry.rb', line 67

def modalities(model:)
  find(model:).modalities
end

#modelsArray<LLM::Registry::Model>

Returns all models as Model objects.

Returns:



47
48
49
# File 'lib/llm/registry.rb', line 47

def models
  @models.map { |id, data| Model.new(data.merge(id:)) }
end