Module: RubyLLM::Protocols::Gemini::Videos

Defined in:
lib/ruby_llm/protocols/gemini/videos.rb

Overview

Veo video generation through the Gemini API's long-running predict operations. The finished video is a Files API URI that requires the API key to download.

Instance Method Summary collapse

Instance Method Details

#download_video(job) ⇒ Object

The file URI answers with a redirect to the download host, and both hops require the API key.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 51

def download_video(job)
  video = generated_video(job.raw)
  response = @connection.get video['uri']
  response = @connection.get response.headers['location'] if response.status / 100 == 3

  Video.new(
    data: response.body,
    mime_type: video['mimeType'] || 'video/mp4',
    model: job.model,
    raw: job.raw
  )
end

#parse_video_job(response, model:) ⇒ Object

Raises:



21
22
23
24
25
26
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 21

def parse_video_job(response, model:)
  name = response.body['name']
  raise Error.new('Gemini did not return a video generation operation', response:) unless name

  VideoJob.new(id: name, protocol: self, model: model, raw: response.body)
end

#parse_video_job_status(response, job:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 37

def parse_video_job_status(response, job:) # rubocop:disable Lint/UnusedMethodArgument
  body = response.body
  if body['error']
    { status: :failed, raw: body, error: body.dig('error', 'message') }
  elsif body['done']
    video = generated_video(body)
    video ? { status: :completed, raw: body } : filtered_video_failure(body)
  else
    { status: :pending, raw: body }
  end
end

#render_video_extension_payload(prompt, extend:, provider_options: {}) ⇒ Object



28
29
30
31
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 28

def render_video_extension_payload(prompt, extend:, provider_options: {}, **)
  video = render_video_extension(extend)
  Support::Utils.deep_merge({ instances: [{ prompt: prompt, video: video }] }, provider_options)
end

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

rubocop:disable Lint/UnusedMethodArgument



14
15
16
17
18
19
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 14

def render_video_payload(prompt, model:, with: [], provider_options: {}) # rubocop:disable Lint/UnusedMethodArgument
  instance = { prompt: prompt }
  instance[:image] = render_video_image(with.first) if with.first

  Support::Utils.deep_merge({ instances: [instance] }, provider_options)
end

#video_job_url(job) ⇒ Object



33
34
35
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 33

def video_job_url(job)
  job.id
end

#video_urlObject



10
11
12
# File 'lib/ruby_llm/protocols/gemini/videos.rb', line 10

def video_url
  "models/#{model_id(@model)}:predictLongRunning"
end