Skip to content

Commit a218e70

Browse files
arnodirlamaltxtech
authored andcommitted
Add tests to RubyLLM::Chat (instead of RubyLLM::ActiveRecord::ActsAs); Update capabilities
1 parent 81c8aba commit a218e70

File tree

6 files changed

+282
-3
lines changed

6 files changed

+282
-3
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ RubyLLM gives you one beautiful API for all of them. Same interface whether you'
9595

9696
```ruby
9797
# Just ask questions
98-
chat = RubyLLM.chat
98+
chat = RubyLLM.chat(model: "gemini-2.0-flash")
9999
chat.ask "What's the best way to learn Ruby?"
100100
```
101101

lib/ruby_llm/providers/gemini/capabilities.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def modalities_for(model_id)
214214

215215
if supports_vision?(model_id)
216216
modalities[:input] << 'image'
217+
modalities[:input] << 'video'
217218
modalities[:input] << 'pdf'
218219
end
219220

spec/fixtures/vcr_cassettes/chat_video_models_gemini_gemini-2_0-flash_can_understand_local_videos.yml

Lines changed: 91 additions & 0 deletions
Large diffs are not rendered by default.

spec/fixtures/vcr_cassettes/chat_video_models_gemini_gemini-2_0-flash_can_understand_remote_videos_without_extension.yml

Lines changed: 156 additions & 0 deletions
Large diffs are not rendered by default.

spec/ruby_llm/active_record/acts_as_attachment_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def uploaded_file(path, type)
8989
expect(attachment.type).to eq(:image)
9090
end
9191

92-
it 'handles videos' do # rubocop:disable RSpec/ExampleLength
92+
it 'handles videos' do
9393
video_path = File.expand_path('../../fixtures/ruby.mp4', __dir__)
94-
chat = Chat.create!(model_id: model)
94+
chat = Chat.create!(model: model)
9595
message = chat.messages.create!(role: 'user', content: 'Video test')
9696

9797
message.attachments.attach(

spec/ruby_llm/chat_content_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
include_context 'with configured RubyLLM'
77

88
let(:image_path) { File.expand_path('../fixtures/ruby.png', __dir__) }
9+
let(:video_path) { File.expand_path('../fixtures/ruby.mp4', __dir__) }
910
let(:audio_path) { File.expand_path('../fixtures/ruby.wav', __dir__) }
1011
let(:mp3_path) { File.expand_path('../fixtures/ruby.mp3', __dir__) }
1112
let(:pdf_path) { File.expand_path('../fixtures/sample.pdf', __dir__) }
1213
let(:text_path) { File.expand_path('../fixtures/ruby.txt', __dir__) }
1314
let(:xml_path) { File.expand_path('../fixtures/ruby.xml', __dir__) }
1415
let(:image_url) { 'https://upload.wikimedia.org/wikipedia/commons/f/f1/Ruby_logo.png' }
16+
let(:video_url) { 'https://filesamples.com/samples/video/mp4/sample_640x360.mp4' }
1517
let(:audio_url) { 'https://commons.wikimedia.org/wiki/File:LL-Q1860_(eng)-AcpoKrane-ruby.wav' }
1618
let(:pdf_url) { 'https://pdfobject.com/pdf/sample.pdf' }
1719
let(:text_url) { 'https://www.ruby-lang.org/en/about/license.txt' }
@@ -96,6 +98,35 @@
9698
end
9799
end
98100

101+
describe 'video models' do # rubocop:disable RSpec/MultipleMemoizedHelpers
102+
VIDEO_MODELS.each do |model_info|
103+
provider = model_info[:provider]
104+
model = model_info[:model]
105+
106+
it "#{provider}/#{model} can understand local videos" do # rubocop:disable RSpec/MultipleExpectations,RSpec/ExampleLength
107+
chat = RubyLLM.chat(model: model, provider: provider)
108+
response = chat.ask('What do you see in this video?', with: { video: video_path })
109+
110+
expect(response.content).to be_present
111+
expect(response.content).not_to include('RubyLLM::Content')
112+
expect(chat.messages.first.content).to be_a(RubyLLM::Content)
113+
expect(chat.messages.first.content.attachments.first.filename).to eq('ruby.mp4')
114+
expect(chat.messages.first.content.attachments.first.mime_type).to eq('video/mp4')
115+
end
116+
117+
it "#{provider}/#{model} can understand remote videos without extension" do # rubocop:disable RSpec/MultipleExpectations,RSpec/ExampleLength
118+
chat = RubyLLM.chat(model: model, provider: provider)
119+
response = chat.ask('What do you see in this video?', with: video_url)
120+
121+
expect(response.content).to be_present
122+
expect(response.content).not_to include('RubyLLM::Content')
123+
expect(chat.messages.first.content).to be_a(RubyLLM::Content)
124+
expect(chat.messages.first.content.attachments.first.filename).to eq('sample_640x360.mp4')
125+
expect(chat.messages.first.content.attachments.first.mime_type).to eq('video/mp4')
126+
end
127+
end
128+
end
129+
99130
describe 'audio models' do # rubocop:disable RSpec/MultipleMemoizedHelpers
100131
AUDIO_MODELS.each do |model_info|
101132
model = model_info[:model]

0 commit comments

Comments
 (0)