Class: LLM::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/registry.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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blob) ⇒ LLM::Registry

Parameters:

  • blob (Hash)

    A model registry



31
32
33
34
# File 'lib/llm/registry.rb', line 31

def initialize(blob)
  @registry = LLM::Object.from(blob)
  @models = @registry.models
end

Class Method Details

.for(name) ⇒ LLM::Registry

Parameters:

  • A (Symbol)

    provider name

Returns:

Raises:



18
19
20
21
22
23
24
25
# File 'lib/llm/registry.rb', line 18

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:



39
40
41
# File 'lib/llm/registry.rb', line 39

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

#modalities(model:) ⇒ LLM::Object

Returns model modalities

Returns:



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

def modalities(model:)
  lookup(model:).modalities
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



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

def limit(model:)
  lookup(model:).limit
end