Module: RubyLLM::Providers::OpenRouter::Media

Defined in:
lib/ruby_llm/providers/openrouter/media.rb

Overview

Handles media content for OpenRouter, which adds video input parts to the standard Chat Completions vocabulary.

Class Method Summary collapse

Class Method Details

.format_content(content, attachments = []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_llm/providers/openrouter/media.rb', line 11

def format_content(content, attachments = [])
  Protocols::ChatCompletions::Media.format_parts(content, attachments) do |attachment|
    if attachment.type == :video
      format_video(attachment)
    else
      Protocols::ChatCompletions::Media.format_attachment(
        attachment, document_attachments: :pdf, image_attachments: true, audio_attachments: true
      )
    end
  end
end

.format_video(video) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ruby_llm/providers/openrouter/media.rb', line 23

def format_video(video)
  {
    type: 'video_url',
    video_url: {
      url: video.url? ? video.source.to_s : video.for_llm
    }
  }
end