Class: Legion::Extensions::Llm::Content
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Content
- Defined in:
- lib/legion/extensions/llm/content.rb,
lib/legion/extensions/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
Allows serializers to store the text payload without custom adapters.
Constructor Details
#initialize(text = nil, attachments = nil) ⇒ Content
Returns a new instance of Content.
10 11 12 13 14 15 16 |
# File 'lib/legion/extensions/llm/content.rb', line 10 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.
8 9 10 |
# File 'lib/legion/extensions/llm/content.rb', line 8 def @attachments end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
8 9 10 |
# File 'lib/legion/extensions/llm/content.rb', line 8 def text @text end |
Instance Method Details
#add_attachment(source, filename: nil) ⇒ Object
18 19 20 21 |
# File 'lib/legion/extensions/llm/content.rb', line 18 def (source, filename: nil) @attachments << Attachment.new(source, filename:) self end |
#format ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/llm/content.rb', line 23 def format if @text && @attachments.empty? @text else self end end |
#to_h ⇒ Object
Allows serializers to store the text payload without custom adapters.
32 33 34 |
# File 'lib/legion/extensions/llm/content.rb', line 32 def to_h { text: @text, attachments: @attachments.map(&:to_h) } end |