Module: RubyLLM::Protocols::Responses::Media
- Defined in:
- lib/ruby_llm/protocols/responses/media.rb
Overview
Handles formatting of media content for the OpenAI Responses API
Class Method Summary collapse
- .format_attachment(attachment) ⇒ Object
- .format_content(content, attachments = []) ⇒ Object
-
.format_document(document) ⇒ Object
The Responses API extracts text from documents, presentations, and spreadsheets as well as PDFs, so every document attachment rides along as a native input_file.
- .format_image(image) ⇒ Object
- .format_provider_file(file) ⇒ Object
Class Method Details
.format_attachment(attachment) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby_llm/protocols/responses/media.rb', line 19 def () return format_provider_file() if .provider_file? case .type when :image format_image() when :pdf, :document format_document() when :text { type: 'input_text', text: .for_llm } else raise UnsupportedAttachmentError, .mime_type end end |
.format_content(content, attachments = []) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/protocols/responses/media.rb', line 10 def format_content(content, = []) return content if .empty? parts = [] parts << { type: 'input_text', text: content } if content .each { || parts << () } parts end |
.format_document(document) ⇒ Object
The Responses API extracts text from documents, presentations, and spreadsheets as well as PDFs, so every document attachment rides along as a native input_file.
44 45 46 47 48 49 50 |
# File 'lib/ruby_llm/protocols/responses/media.rb', line 44 def format_document(document) { type: 'input_file', filename: document.filename, file_data: document.for_llm } end |
.format_image(image) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ruby_llm/protocols/responses/media.rb', line 34 def format_image(image) { type: 'input_image', image_url: image.url? ? image.source.to_s : image.for_llm } end |
.format_provider_file(file) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/ruby_llm/protocols/responses/media.rb', line 52 def format_provider_file(file) { type: 'input_file', file_id: file.provider_file_id } end |