Class: RubyLLM::Content
- Inherits:
-
Object
- Object
- RubyLLM::Content
- Defined in:
- lib/ruby_llm/content.rb,
lib/ruby_llm/content.rb
Overview
Represents the content sent to or received from an LLM.
Defined Under Namespace
Classes: Raw
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #add_attachment(source, filename: nil) ⇒ Object
- #format ⇒ Object
-
#initialize(text = nil, attachments = nil) ⇒ Content
constructor
A new instance of Content.
-
#to_h ⇒ Object
For Rails serialization.
Constructor Details
#initialize(text = nil, attachments = nil) ⇒ Content
Returns a new instance of Content.
8 9 10 11 12 13 14 |
# File 'lib/ruby_llm/content.rb', line 8 def initialize(text = nil, = nil) @text = text @attachments = [] () raise ArgumentError, 'Text and attachments cannot be both nil' if @text.nil? && @attachments.empty? end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
6 7 8 |
# File 'lib/ruby_llm/content.rb', line 6 def @attachments end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/ruby_llm/content.rb', line 6 def text @text end |
Instance Method Details
#add_attachment(source, filename: nil) ⇒ Object
16 17 18 19 |
# File 'lib/ruby_llm/content.rb', line 16 def (source, filename: nil) @attachments << Attachment.new(source, filename:) self end |
#format ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ruby_llm/content.rb', line 21 def format if @text && @attachments.empty? @text else self end end |
#to_h ⇒ Object
For Rails serialization
30 31 32 |
# File 'lib/ruby_llm/content.rb', line 30 def to_h { text: @text, attachments: @attachments.map(&:to_h) } end |