Module: RubyLLM::Pollinations::Provider::Media

Included in:
Pollinations
Defined in:
lib/ruby_llm/pollinations/provider/media.rb

Class Method Summary collapse

Class Method Details

.format_audio(audio) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 61

def format_audio(audio)
  {
    type: 'input_audio',
    input_audio: {
      data: audio.encoded,
      format: audio.format
    }
  }
end

.format_content(content) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 9

def format_content(content) # rubocop:disable Metrics/PerceivedComplexity
  return content.value if content.is_a?(RubyLLM::Content::Raw)
  return content.to_json if content.is_a?(Hash) || content.is_a?(Array)
  return content unless content.is_a?(RubyLLM::Content)

  parts = []
  parts << format_text(content.text) if content.text

  content.attachments.each do |attachment|
    case attachment.type
    when :image
      parts << format_image(attachment)
    when :pdf
      parts << format_pdf(attachment)
    when :audio
      parts << format_audio(attachment)
    when :text
      parts << format_text_file(attachment)
    else
      raise RubyLLM::UnsupportedAttachmentError, attachment.type
    end
  end

  parts
end

.format_image(image) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 35

def format_image(image)
  {
    type: 'image_url',
    image_url: {
      url: image.url? ? image.source.to_s : image.for_llm
    }
  }
end

.format_pdf(pdf) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 44

def format_pdf(pdf)
  {
    type: 'file',
    file: {
      filename: pdf.filename,
      file_data: pdf.for_llm
    }
  }
end

.format_text(text) ⇒ Object



71
72
73
74
75
76
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 71

def format_text(text)
  {
    type: 'text',
    text: text
  }
end

.format_text_file(text_file) ⇒ Object



54
55
56
57
58
59
# File 'lib/ruby_llm/pollinations/provider/media.rb', line 54

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