Module: RubyLLM::Protocols::Gemini::Media

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

Overview

Media handling methods for the Gemini API integration

Class Method Summary collapse

Class Method Details

.format_attachment(attachment) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 35

def format_attachment(attachment)
  return format_file_data(attachment) if attachment.provider_file?

  {
    inline_data: {
      mime_type: attachment.mime_type,
      data: attachment.encoded
    }
  }
end

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



13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 13

def format_content(content, attachments = [])
  parts = []
  parts << format_text(content) if content

  attachments.each do |attachment|
    parts << format_content_attachment(attachment)
  end

  parts
end

.format_content_attachment(attachment) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 24

def format_content_attachment(attachment)
  case attachment.type
  when :text
    format_text_file(attachment)
  when :document, :unknown
    raise UnsupportedAttachmentError, attachment.mime_type
  else
    format_attachment(attachment)
  end
end

.format_file_data(attachment) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 46

def format_file_data(attachment)
  uri = attachment.provider_file_uri || attachment.provider_file_id
  {
    file_data: {
      mime_type: attachment.mime_type,
      file_uri: uri
    }
  }
end

.format_text(text) ⇒ Object



62
63
64
65
66
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 62

def format_text(text)
  {
    text: text
  }
end

.format_text_file(text_file) ⇒ Object



56
57
58
59
60
# File 'lib/ruby_llm/protocols/gemini/media.rb', line 56

def format_text_file(text_file)
  {
    text: text_file.for_llm
  }
end