Class: ActiveIntelligence::Chat

Inherits:
ApplicationRecord show all
Includes:
Promptable
Defined in:
app/models/active_intelligence/chat.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/models/active_intelligence/chat.rb', line 12

def as_json(options = {})
  if options.empty?
    options[:only] = %i[id created_at updated_at]
    options[:methods] = %i[messages_count]
    options[:include] = [messages: { only: %i[id role content created_at updated_at] }]
  end

  super(options)
end

#reply(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/models/active_intelligence/chat.rb', line 22

def reply(options = {})
  options = options.dup
  llm = ActiveIntelligence::LLM::Config.new.adapter(options[:adapter])
  prompt = options.delete(:prompt) || to_prompt(options.delete(:name))

  reply = llm.reply(self, prompt, options)
  return messages.create!(role: 'assistant', content: reply)
end