Skip to content

Commit 7a8daa1

Browse files
arnodirlamaltxtech
authored andcommitted
Add video file support to attachments
1 parent fa10f0c commit 7a8daa1

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib/ruby_llm/attachment.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def for_llm
7676

7777
def type
7878
return :image if image?
79+
return :video if video?
7980
return :audio if audio?
8081
return :pdf if pdf?
8182
return :text if text?
@@ -87,6 +88,10 @@ def image?
8788
RubyLLM::MimeType.image? mime_type
8889
end
8990

91+
def video?
92+
RubyLLM::MimeType.video? mime_type
93+
end
94+
9095
def audio?
9196
RubyLLM::MimeType.audio? mime_type
9297
end

lib/ruby_llm/mime_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def image?(type)
1515
type.start_with?('image/')
1616
end
1717

18+
def video?(type)
19+
type.start_with?('video/')
20+
end
21+
1822
def audio?(type)
1923
type.start_with?('audio/')
2024
end

spec/fixtures/ruby.mp4

561 KB
Binary file not shown.

spec/ruby_llm/active_record/acts_as_attachment_spec.rb

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

92+
it 'handles videos' do # rubocop:disable RSpec/ExampleLength
93+
video_path = File.expand_path('../../fixtures/ruby.mp4', __dir__)
94+
chat = Chat.create!(model_id: model)
95+
message = chat.messages.create!(role: 'user', content: 'Video test')
96+
97+
message.attachments.attach(
98+
io: File.open(video_path),
99+
filename: 'test.mp4',
100+
content_type: 'video/mp4'
101+
)
102+
103+
llm_message = message.to_llm
104+
attachment = llm_message.content.attachments.first
105+
expect(attachment.type).to eq(:video)
106+
end
107+
92108
it 'handles PDFs' do
93109
chat = Chat.create!(model: model)
94110
message = chat.messages.create!(role: 'user', content: 'PDF test')

0 commit comments

Comments
 (0)