Module: RubyLLM::Models

Defined in:
lib/ruby_llm/models.rb

Class Method Summary collapse

Class Method Details

.allObject



11
12
13
14
15
16
17
18
# File 'lib/ruby_llm/models.rb', line 11

def all
  @all ||= begin
    data = JSON.parse(File.read(File.expand_path('models.json', __dir__)))
    data['models'].map { |model| ModelInfo.new(model.transform_keys(&:to_sym)) }
  end
rescue Errno::ENOENT
  [] # Return empty array if file doesn't exist yet
end

.audio_modelsObject



32
33
34
# File 'lib/ruby_llm/models.rb', line 32

def audio_models
  all.select { |m| m.type == 'audio' }
end

.by_family(family) ⇒ Object



40
41
42
# File 'lib/ruby_llm/models.rb', line 40

def by_family(family)
  all.select { |m| m.family == family }
end

.chat_modelsObject



24
25
26
# File 'lib/ruby_llm/models.rb', line 24

def chat_models
  all.select { |m| m.type == 'chat' }
end

.default_modelObject



44
45
46
# File 'lib/ruby_llm/models.rb', line 44

def default_model
  'gpt-4o-mini'
end

.embedding_modelsObject



28
29
30
# File 'lib/ruby_llm/models.rb', line 28

def embedding_models
  all.select { |m| m.type == 'embedding' }
end

.find(model_id) ⇒ Object



20
21
22
# File 'lib/ruby_llm/models.rb', line 20

def find(model_id)
  all.find { |m| m.id == model_id } or raise Error, "Unknown model: #{model_id}"
end

.image_modelsObject



36
37
38
# File 'lib/ruby_llm/models.rb', line 36

def image_models
  all.select { |m| m.type == 'image' }
end

.provider_for(model) ⇒ Object



7
8
9
# File 'lib/ruby_llm/models.rb', line 7

def provider_for(model)
  Provider.for(model)
end

.refresh!Object



48
49
50
# File 'lib/ruby_llm/models.rb', line 48

def refresh!
  @all = nil
end