Module: RubyLLM::Providers::XAI::Videos

Included in:
Responses
Defined in:
lib/ruby_llm/providers/xai/videos.rb

Overview

Grok Imagine generation, editing, and extension jobs.

Instance Method Summary collapse

Instance Method Details

#download_video(job) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby_llm/providers/xai/videos.rb', line 55

def download_video(job)
  video = job.raw['video'] || {}

  Video.new(
    url: video['url'],
    mime_type: 'video/mp4',
    duration: video['duration'],
    model: job.raw['model'] || job.model,
    raw: job.raw
  )
end

#parse_video_job(response, model:) ⇒ Object

Raises:



35
36
37
38
39
40
# File 'lib/ruby_llm/providers/xai/videos.rb', line 35

def parse_video_job(response, model:)
  id = response.body['request_id']
  raise Error.new('xAI did not return a video request id', response:) unless id

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

#parse_video_job_status(response, job:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



46
47
48
49
50
51
52
53
# File 'lib/ruby_llm/providers/xai/videos.rb', line 46

def parse_video_job_status(response, job:) # rubocop:disable Lint/UnusedMethodArgument
  body = response.body
  case body['status']
  when 'done' then { status: :completed, raw: body }
  when 'failed', 'expired' then { status: :failed, raw: body, error: body['error'] || body['status'] }
  else { status: :pending, raw: body }
  end
end

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



30
31
32
33
# File 'lib/ruby_llm/providers/xai/videos.rb', line 30

def render_video_extension_payload(prompt, model:, extend:, provider_options: {})
  video = video_extension_attachment(extend)
  { model: model, prompt: prompt, video: video_reference(video) }.merge(provider_options)
end

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



20
21
22
23
24
25
26
27
28
# File 'lib/ruby_llm/providers/xai/videos.rb', line 20

def render_video_payload(prompt, model:, with: [], provider_options: {})
  payload = { model: model, prompt: prompt }
  if (attachment = with.first)
    key = attachment.video? ? :video : :image
    payload[key] = video_reference(attachment)
  end

  payload.merge(provider_options)
end

#video_extension_urlObject



16
17
18
# File 'lib/ruby_llm/providers/xai/videos.rb', line 16

def video_extension_url
  'videos/extensions'
end

#video_job_url(job) ⇒ Object



42
43
44
# File 'lib/ruby_llm/providers/xai/videos.rb', line 42

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

#video_request_url(payload) ⇒ Object



12
13
14
# File 'lib/ruby_llm/providers/xai/videos.rb', line 12

def video_request_url(payload)
  payload.key?(:video) ? 'videos/edits' : video_url
end

#video_urlObject



8
9
10
# File 'lib/ruby_llm/providers/xai/videos.rb', line 8

def video_url
  'videos/generations'
end