Module: RubyLLM::Models
- Defined in:
- lib/ruby_llm/models.rb
Overview
Registry of available AI models and their capabilities. Provides a clean interface to discover and work with models from different providers.
Example:
RubyLLM.models.all # All available models
RubyLLM.models.chat_models # Models that support chat
RubyLLM.models.find('claude-3') # Get info about a specific model
Class Method Summary collapse
- .all ⇒ Object
- .audio_models ⇒ Object
- .by_family(family) ⇒ Object
- .chat_models ⇒ Object
- .default_model ⇒ Object
- .embedding_models ⇒ Object
- .find(model_id) ⇒ Object
- .image_models ⇒ Object
- .provider_for(model) ⇒ Object
- .refresh! ⇒ Object
Class Method Details
.all ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ruby_llm/models.rb', line 18 def all @all ||= begin data = JSON.parse(File.read(File.('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_models ⇒ Object
39 40 41 |
# File 'lib/ruby_llm/models.rb', line 39 def audio_models all.select { |m| m.type == 'audio' } end |
.by_family(family) ⇒ Object
47 48 49 |
# File 'lib/ruby_llm/models.rb', line 47 def by_family(family) all.select { |m| m.family == family } end |
.chat_models ⇒ Object
31 32 33 |
# File 'lib/ruby_llm/models.rb', line 31 def chat_models all.select { |m| m.type == 'chat' } end |
.default_model ⇒ Object
51 52 53 |
# File 'lib/ruby_llm/models.rb', line 51 def default_model 'gpt-4o-mini' end |
.embedding_models ⇒ Object
35 36 37 |
# File 'lib/ruby_llm/models.rb', line 35 def all.select { |m| m.type == 'embedding' } end |
.find(model_id) ⇒ Object
27 28 29 |
# File 'lib/ruby_llm/models.rb', line 27 def find(model_id) all.find { |m| m.id == model_id } or raise Error, "Unknown model: #{model_id}" end |
.image_models ⇒ Object
43 44 45 |
# File 'lib/ruby_llm/models.rb', line 43 def image_models all.select { |m| m.type == 'image' } end |
.provider_for(model) ⇒ Object
14 15 16 |
# File 'lib/ruby_llm/models.rb', line 14 def provider_for(model) Provider.for(model) end |
.refresh! ⇒ Object
55 56 57 |
# File 'lib/ruby_llm/models.rb', line 55 def refresh! @all = nil end |