Module: RubyLLM::Providers::Perplexity::Media
- Defined in:
- lib/ruby_llm/providers/perplexity/media.rb
Overview
Handles Perplexity Sonar media content.
Constant Summary collapse
- SUPPORTED_DOCUMENT_EXTENSIONS =
%w[pdf doc docx txt rtf].freeze
Class Method Summary collapse
-
.format_content(content) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- .format_document(attachment) ⇒ Object
- .format_text_attachment(attachment) ⇒ Object
- .supported_file?(attachment) ⇒ Boolean
Class Method Details
.format_content(content) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_llm/providers/perplexity/media.rb', line 12 def format_content(content) # rubocop:disable Metrics/PerceivedComplexity if content.is_a?(RubyLLM::Content::Raw) value = content.value return value.is_a?(Hash) ? value.to_json : value end return content.to_json if content.is_a?(Hash) || content.is_a?(Array) return content unless content.is_a?(Content) parts = [] parts << OpenAI::Media.format_text(content.text) if content.text content..each do || case .type when :image parts << OpenAI::Media.format_image() when :pdf, :document parts << format_document() when :text parts << () else raise UnsupportedAttachmentError, .mime_type end end parts end |
.format_document(attachment) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/providers/perplexity/media.rb', line 39 def format_document() raise UnsupportedAttachmentError, .mime_type unless supported_file?() { type: 'file_url', file_url: { url: .url? ? .source.to_s : .encoded } } end |
.format_text_attachment(attachment) ⇒ Object
50 51 52 |
# File 'lib/ruby_llm/providers/perplexity/media.rb', line 50 def () OpenAI::Media.format_text_file() end |
.supported_file?(attachment) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/ruby_llm/providers/perplexity/media.rb', line 54 def supported_file?() return true if .pdf? SUPPORTED_DOCUMENT_EXTENSIONS.include?(.extension) end |