class RubyLLM::Content
Represents the content sent to or received from an LLM.
Attributes
Public Class Methods
# File lib/ruby_llm/content.rb, line 8 def initialize(text = nil, attachments = nil) @text = text @attachments = [] process_attachments(attachments) raise ArgumentError, 'Text and attachments cannot be both nil' if @text.nil? && @attachments.empty? end
Public Instance Methods
# File lib/ruby_llm/content.rb, line 16 def add_attachment(source, filename: nil) @attachments << build_attachment(source, filename:) self end
Source
# File lib/ruby_llm/content.rb, line 29 def empty? attachments.empty? && (@text.nil? || (@text.respond_to?(:empty?) && @text.empty?)) end
Source
# File lib/ruby_llm/content.rb, line 21 def format if @text && @attachments.empty? @text else self end end
Source
# File lib/ruby_llm/content.rb, line 34 def to_h { text: @text, attachments: @attachments.map(&:to_h) } end
For Rails serialization