Class: Ruboty::OpenAIChat::Memory
- Inherits:
-
Object
- Object
- Ruboty::OpenAIChat::Memory
- Defined in:
- lib/ruboty/openai_chat/memory.rb
Instance Attribute Summary collapse
- #robot ⇒ Ruboty::Robot readonly
Instance Method Summary collapse
- #delete(*prefix, key) ⇒ Object
- #dig(*keys) ⇒ Object?
-
#initialize(robot) ⇒ Memory
constructor
A new instance of Memory.
- #namespace(*keys) ⇒ Hash
Constructor Details
#initialize(robot) ⇒ Memory
Returns a new instance of Memory.
10 11 12 |
# File 'lib/ruboty/openai_chat/memory.rb', line 10 def initialize(robot) @robot = robot end |
Instance Attribute Details
#robot ⇒ Ruboty::Robot (readonly)
7 8 9 |
# File 'lib/ruboty/openai_chat/memory.rb', line 7 def robot @robot end |
Instance Method Details
#delete(*prefix, key) ⇒ Object
24 25 26 |
# File 'lib/ruboty/openai_chat/memory.rb', line 24 def delete(*prefix, key) dig(*prefix)&.delete(key) end |
#dig(*keys) ⇒ Object?
30 31 32 |
# File 'lib/ruboty/openai_chat/memory.rb', line 30 def dig(*keys) keys.empty? ? robot.brain.data : robot.brain.data.dig(*keys) end |
#namespace(*keys) ⇒ Hash
16 17 18 19 20 |
# File 'lib/ruboty/openai_chat/memory.rb', line 16 def namespace(*keys) keys.reduce(robot.brain.data) do |data, key| data[key] ||= {} end end |