Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ruby_llm/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ def chat_models
end

def embedding_models
self.class.new(all.select { |m| m.type == 'embedding' })
self.class.new(all.select { |m| m.type == 'embedding' || m.modalities.output.include?('embeddings') })
end

def audio_models
self.class.new(all.select { |m| m.type == 'audio' })
self.class.new(all.select { |m| m.type == 'audio' || m.modalities.output.include?('audio') })
end

def image_models
self.class.new(all.select { |m| m.type == 'image' })
self.class.new(all.select { |m| m.type == 'image' || m.modalities.output.include?('image') })
end

def by_family(family)
Expand Down
28 changes: 22 additions & 6 deletions spec/ruby_llm/models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,47 @@
end

describe '#embedding_models' do
it 'filters to only embedding models' do
it 'filters to models that are embedding-capable' do
embedding_models = RubyLLM.models.embedding_models

expect(embedding_models).to be_a(described_class)
expect(embedding_models.all).to all(have_attributes(type: 'embedding'))
expect(embedding_models.all).not_to be_empty

expect(embedding_models.all).to all(
satisfy('has type=embedding or output includes embeddings') { |m|
m.type == 'embedding' || Array(m.modalities&.output).include?('embeddings')
}
)
end
end

describe '#audio_models' do
it 'filters to only audio models' do
it 'filters to models that are audio-capable' do
audio_models = RubyLLM.models.audio_models

expect(audio_models).to be_a(described_class)
expect(audio_models.all).to all(have_attributes(type: 'audio'))
expect(audio_models.all).not_to be_empty

expect(audio_models.all).to all(
satisfy('has type=audio or output includes audio') { |m|
m.type == 'audio' || Array(m.modalities&.output).include?('audio')
}
)
end
end

describe '#image_models' do
it 'filters to only image models' do
it 'filters to models that are image-capable' do
image_models = RubyLLM.models.image_models

expect(image_models).to be_a(described_class)
expect(image_models.all).to all(have_attributes(type: 'image'))
expect(image_models.all).not_to be_empty

expect(image_models.all).to all(
satisfy('has type=image or output includes image') { |m|
m.type == 'image' || Array(m.modalities&.output).include?('image')
}
)
end
end

Expand Down