Class: Luo::Messages
- Inherits:
-
Object
- Object
- Luo::Messages
- Defined in:
- lib/luo/messages.rb
Class Method Summary collapse
- .create(history: nil) ⇒ Object
- .create_role_message_method(role) ⇒ Object
- .create_role_message_methods ⇒ Object
Instance Method Summary collapse
-
#initialize(history: []) ⇒ Messages
constructor
A new instance of Messages.
- #to_a ⇒ Object
Constructor Details
#initialize(history: []) ⇒ Messages
Returns a new instance of Messages.
5 6 7 8 9 |
# File 'lib/luo/messages.rb', line 5 def initialize(history: []) @history = history = [] @system = {} end |
Class Method Details
.create(history: nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/luo/messages.rb', line 44 def create(history: nil) if history self.new(history: history) else self.new(history: []) end end |
.create_role_message_method(role) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/luo/messages.rb', line 11 def self.(role) define_method(role) do |text: nil, file: '', prompt: nil, context: {}| if prompt.nil? data = text || File.read(file) else data = prompt.render(context) end if role.to_s == "system" @system = {role: role, content: data} else << {role: role, content: data} end self end end |
.create_role_message_methods ⇒ Object
27 28 29 30 31 |
# File 'lib/luo/messages.rb', line 27 def self. %w(system user assistant).each do |role| (role) end end |
Instance Method Details
#to_a ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/luo/messages.rb', line 35 def to_a if @system.empty? @history.to_a + else (@history.to_a + ).unshift(@system) end end |