Module: RubyLLM::Providers::OpenAIResponses::Media
- Included in:
- RubyLLM::Providers::OpenAIResponses
- Defined in:
- lib/ruby_llm/providers/openai_responses/media.rb
Overview
Media handling methods for the OpenAI Responses API. Handles images, audio, PDFs, and other file types.
Class Method Summary collapse
- .detect_audio_format(source) ⇒ Object
- .extract_filename(source) ⇒ Object
- .format_attachment(attachment) ⇒ Object
- .format_audio(audio) ⇒ Object
- .format_image(image) ⇒ Object
- .format_pdf(pdf) ⇒ Object
- .format_text_file(text_file) ⇒ Object
Class Method Details
.detect_audio_format(source) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 73 def detect_audio_format(source) return 'mp3' unless source ext = if source.respond_to?(:path) File.extname(source.path) else File.extname(source.to_s) end case ext.downcase when '.mp3' then 'mp3' when '.wav' then 'wav' when '.webm' then 'webm' when '.ogg' then 'ogg' when '.flac' then 'flac' when '.m4a' then 'm4a' else 'mp3' end end |
.extract_filename(source) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 63 def extract_filename(source) return 'file' unless source if source.respond_to?(:path) File.basename(source.path) else File.basename(source.to_s) end end |
.format_attachment(attachment) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 11 def () case .type when :image format_image() when :pdf format_pdf() when :audio format_audio() when :text format_text_file() else raise UnsupportedAttachmentError, .type end end |
.format_audio(audio) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 48 def format_audio(audio) { type: 'input_audio', data: audio.for_llm, format: detect_audio_format(audio.source) } end |
.format_image(image) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 26 def format_image(image) if image.url? { type: 'input_image', image_url: image.source } else { type: 'input_image', image_url: image.for_llm } end end |
.format_pdf(pdf) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 40 def format_pdf(pdf) { type: 'input_file', filename: extract_filename(pdf.source), file_data: pdf.for_llm } end |
.format_text_file(text_file) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ruby_llm/providers/openai_responses/media.rb', line 56 def format_text_file(text_file) { type: 'input_text', text: text_file.for_llm } end |