Class: OpenAISwarm::Memory
- Inherits:
-
Object
- Object
- OpenAISwarm::Memory
- Defined in:
- lib/ruby-openai-swarm/memory.rb
Instance Attribute Summary collapse
-
#entity_store ⇒ Object
readonly
Returns the value of attribute entity_store.
-
#memories ⇒ Object
readonly
Returns the value of attribute memories.
Instance Method Summary collapse
- #core_memory_save(entities) ⇒ Object
- #core_memory_save_metadata ⇒ Object
- #function ⇒ Object
- #get_memories_data ⇒ Object
-
#initialize(memory_fields: [], entity_store: nil) ⇒ Memory
constructor
A new instance of Memory.
- #normalize_memory_fields(memory_fields) ⇒ Object
- #prompt_content ⇒ Object
Constructor Details
#initialize(memory_fields: [], entity_store: nil) ⇒ Memory
6 7 8 9 |
# File 'lib/ruby-openai-swarm/memory.rb', line 6 def initialize(memory_fields: [], entity_store: nil) @memory_fields = normalize_memory_fields(memory_fields) @entity_store = Memories::EntityStore.new(entity_store) end |
Instance Attribute Details
#entity_store ⇒ Object (readonly)
Returns the value of attribute entity_store.
3 4 5 |
# File 'lib/ruby-openai-swarm/memory.rb', line 3 def entity_store @entity_store end |
#memories ⇒ Object (readonly)
Returns the value of attribute memories.
3 4 5 |
# File 'lib/ruby-openai-swarm/memory.rb', line 3 def memories @memories end |
Instance Method Details
#core_memory_save(entities) ⇒ Object
17 18 19 |
# File 'lib/ruby-openai-swarm/memory.rb', line 17 def core_memory_save(entities) entity_store.add_entities(entities) end |
#core_memory_save_metadata ⇒ Object
41 42 43 |
# File 'lib/ruby-openai-swarm/memory.rb', line 41 def ||= Memories::CoreMemoryFunction.definition(@memory_fields) end |
#function ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby-openai-swarm/memory.rb', line 31 def function return nil if @memory_fields.empty? OpenAISwarm::FunctionDescriptor.new( target_method: method(:core_memory_save), description: [:function][:description], parameters: [:function][:parameters] ) end |
#get_memories_data ⇒ Object
45 46 47 |
# File 'lib/ruby-openai-swarm/memory.rb', line 45 def get_memories_data entity_store&.memories end |
#normalize_memory_fields(memory_fields) ⇒ Object
11 12 13 14 15 |
# File 'lib/ruby-openai-swarm/memory.rb', line 11 def normalize_memory_fields(memory_fields) return [] if memory_fields.empty? memory_fields.map { |memory_field| Memories::Field.new(memory_field) } end |
#prompt_content ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby-openai-swarm/memory.rb', line 21 def prompt_content return nil if get_memories_data.nil? fields = @memory_fields.map(&:field).join(", ") "You have a section of your context called [MEMORY] " \ "that contains the following information: #{fields}. " \ "Here are the relevant details: [MEMORY]\n" \ "#{get_memories_data}" end |