Module: RubyLLM::Protocols::ElevenLabs::Flows::Videos

Defined in:
lib/ruby_llm/protocols/elevenlabs/flows/videos.rb

Overview

:nodoc: all

Constant Summary collapse

REFERENCE_VIDEO_MODELS =
%w[
  bytedance-seedance-v2 bytedance-seedance-v2-fast bytedance-seedance-v2-mini bytedance-seedance-v2.5
].freeze

Instance Method Summary collapse

Instance Method Details

#download_video(job) ⇒ Object



77
78
79
80
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 77

def download_video(job)
  Video.new(url: job.raw.fetch('content_url'), mime_type: job.raw.fetch('content_mime_type'),
            model: job.model, raw: job.raw)
end

#parse_video_job(response, model:) ⇒ Object



65
66
67
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 65

def parse_video_job(response, model:)
  VideoJob.new(id: response.body.fetch('id'), protocol: self, model:, raw: response.body)
end

#parse_video_job_status(response) ⇒ Object



73
74
75
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 73

def parse_video_job_status(response, **)
  parse_generation_status(response.body)
end

#render_character_animation(prompt, with:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 40

def render_character_animation(prompt, with:)
  unless prompt.nil? || prompt.empty?
    raise ArgumentError, 'Creatify Aurora uses image and audio input; omit the prompt'
  end

  image = with.select(&:image?)
  audio = with.select(&:audio?)
  unless with.size == 2 && image.one? && audio.one?
    raise ArgumentError, 'Creatify Aurora requires exactly one image and one audio attachment'
  end

  { image: render_media_reference(image.first), audio: render_media_reference(audio.first) }
end

#render_video_inputs(prompt, model:, with:) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 25

def render_video_inputs(prompt, model:, with:)
  raise ArgumentError, 'This ElevenLabs video model requires a prompt' if prompt.to_s.empty?

  payload = { prompt: }
  if with.all?(&:image?)
    raise ArgumentError, 'Video generation accepts at most two frame images' if with.size > 2

    payload[:start_frame] = render_media_reference(with[0]) if with[0]
    payload[:end_frame] = render_media_reference(with[1]) if with[1]
  else
    render_video_references(payload, with, model:)
  end
  payload
end

#render_video_payload(prompt, model:, with: [], provider_options: {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 16

def render_video_payload(prompt, model:, with: [], provider_options: {})
  payload = if model == 'creatify-aurora'
              render_character_animation(prompt, with:)
            else
              render_video_inputs(prompt, model:, with:)
            end
  Support::Utils.deep_merge({ model_id: model }.merge(payload), provider_options)
end

#render_video_references(payload, attachments, model:) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 54

def render_video_references(payload, attachments, model:)
  unless REFERENCE_VIDEO_MODELS.include?(model)
    raise ArgumentError, 'This ElevenLabs video model only accepts image attachments'
  end

  { images: :image?, audios: :audio?, videos: :video? }.each do |field, predicate|
    references = attachments.select { |attachment| attachment.public_send(predicate) }
    payload[field] = references.map { |attachment| render_media_reference(attachment) } if references.any?
  end
end

#validate_animate_inputs!(with:) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 82

def validate_animate_inputs!(with:)
  with.each do |attachment|
    unless attachment.image? || attachment.audio? || attachment.video?
      raise UnsupportedAttachmentError, attachment.mime_type
    end
  end
end

#video_job_url(job) ⇒ Object



69
70
71
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 69

def video_job_url(job)
  "#{video_url}/#{job.id}"
end

#video_urlObject



12
13
14
# File 'lib/ruby_llm/protocols/elevenlabs/flows/videos.rb', line 12

def video_url
  'v1/flows/video'
end