Class: ActiveAI::Behavior::LLM::Conversation
- Inherits:
-
ActiveAI::Behavior::LLM
- Object
- Base
- ActiveAI::Behavior::LLM
- ActiveAI::Behavior::LLM::Conversation
- Defined in:
- lib/activeai/behavior/llm/conversation.rb
Constant Summary
Constants inherited from ActiveAI::Behavior::LLM
Instance Method Summary collapse
- #add(speaker, message) ⇒ Object
- #get_reply(prefix: nil) ⇒ Object
- #history ⇒ Object
-
#initialize(llm, state) ⇒ Conversation
constructor
i need alerts if this stuff gets caught in a loop! like pondering->noticing and never stopping or something.
- #prompt ⇒ Object
Methods inherited from ActiveAI::Behavior::LLM
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, ) comms = "#{speaker}: #{.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 |
#history ⇒ Object
11 12 13 |
# File 'lib/activeai/behavior/llm/conversation.rb', line 11 def history @state['conversation'] end |
#prompt ⇒ Object
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 |