Class: ActiveAI::Behavior::LLM::Conversation

Inherits:
ActiveAI::Behavior::LLM show all
Defined in:
lib/activeai/behavior/llm/conversation.rb

Constant Summary

Constants inherited from ActiveAI::Behavior::LLM

LINE_SEPARATOR

Instance Method Summary collapse

Methods inherited from ActiveAI::Behavior::LLM

#complete, #extract_keys

Constructor Details

#initialize(llm, state) ⇒ Conversation

i need alerts if this stuff gets caught in a loop! like pondering->noticing and never stopping or something



4
5
6
7
8
9
# File 'lib/activeai/behavior/llm/conversation.rb', line 4

def initialize(llm, state)
  super(llm)
  @state = state
  # TODO raise errors if not expected thingies available in the config
  @state['conversation'] ||= ""
end

Instance Method Details

#add(speaker, message) ⇒ Object



26
27
28
29
# File 'lib/activeai/behavior/llm/conversation.rb', line 26

def add(speaker, message)
  comms = "#{speaker}: #{message.strip}"
  @state['conversation'] += comms + "\n"
end

#get_reply(prefix: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/activeai/behavior/llm/conversation.rb', line 31

def get_reply(prefix: nil)
  @state['conversation'] += prefix if prefix

  complete_result = complete(prompt, stop: "\n")
  completion = complete_result['choices'][0]['text']

  @state['conversation'] += completion + "\n"

  completion
end

#historyObject



11
12
13
# File 'lib/activeai/behavior/llm/conversation.rb', line 11

def history
  @state['conversation']
end

#promptObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/activeai/behavior/llm/conversation.rb', line 15

def prompt
  [
    @state['instruction'],
    @state['examples'].map do |example|
      "Example Conversation:\n" + example['conversation']
      # TODO use the label key they provide in the yml file
    end,
    "Conversation:\n" + @state['conversation']
  ].join(LINE_SEPARATOR)
end