Class: Ruboty::OpenAIChat::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/openai_chat/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ Memory

Returns a new instance of Memory.

Parameters:

  • robot (Ruboty::Robot)


10
11
12
# File 'lib/ruboty/openai_chat/memory.rb', line 10

def initialize(robot)
  @robot = robot
end

Instance Attribute Details

#robotRuboty::Robot (readonly)

Returns:

  • (Ruboty::Robot)


7
8
9
# File 'lib/ruboty/openai_chat/memory.rb', line 7

def robot
  @robot
end

Instance Method Details

#delete(*prefix, key) ⇒ Object

Parameters:

  • prefix (Array<String, Symbol>)
  • key (String, Symbol)


24
25
26
# File 'lib/ruboty/openai_chat/memory.rb', line 24

def delete(*prefix, key)
  dig(*prefix)&.delete(key)
end

#dig(*keys) ⇒ Object?

Parameters:

  • keys (Array<String, Symbol>)

Returns:

  • (Object, nil)


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

Parameters:

  • keys (Array<String, Symbol>)

Returns:

  • (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