Module: RubyLLM::Providers::Ollama::Media

Extended by:
RubyLLM::Providers::OpenAI::Media
Included in:
RubyLLM::Providers::Ollama
Defined in:
lib/ruby_llm/providers/ollama/media.rb

Overview

Handles formatting of media content (images, audio) for Ollama APIs

Class Method Summary collapse

Methods included from RubyLLM::Providers::OpenAI::Media

format_audio, format_pdf, format_text, format_text_file

Class Method Details

.format_content(content) ⇒ Object



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

def format_content(content)
  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?(Content)

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

  content.attachments.each do |attachment|
    case attachment.type
    when :image
      parts << Ollama::Media.format_image(attachment)
    when :text
      parts << format_text_file(attachment)
    else
      raise UnsupportedAttachmentError, attachment.mime_type
    end
  end

  parts
end

.format_image(image) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ruby_llm/providers/ollama/media.rb', line 34

def format_image(image)
  {
    type: 'image_url',
    image_url: {
      url: image.for_llm,
      detail: 'auto'
    }
  }
end