Module: RubyLLM::Providers::Mistral::Media
- Defined in:
- lib/ruby_llm/providers/mistral/media.rb
Overview
Handles media content for Mistral Chat Completions.
Class Method Summary collapse
-
.format_content(content) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- .format_document(document) ⇒ Object
- .format_image(image) ⇒ Object
Class Method Details
.format_content(content) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
10 11 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/mistral/media.rb', line 10 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 << format_image() when :audio parts << OpenAI::Media.format_audio() when :pdf, :document parts << format_document() when :text parts << OpenAI::Media.format_text_file() else raise UnsupportedAttachmentError, .mime_type end end parts end |
.format_document(document) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ruby_llm/providers/mistral/media.rb', line 46 def format_document(document) { type: 'document_url', document_url: document.url? ? document.source.to_s : document.for_llm } end |
.format_image(image) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ruby_llm/providers/mistral/media.rb', line 39 def format_image(image) { type: 'image_url', image_url: image.url? ? image.source.to_s : image.for_llm } end |