Spaces:
Runtime error
Runtime error
Update src/memory.py
Browse files- src/memory.py +16 -1
src/memory.py
CHANGED
|
@@ -66,4 +66,19 @@ class EnhancedInMemoryHistory(BaseMemory):
|
|
| 66 |
|
| 67 |
def clear_memory(self):
|
| 68 |
"""Clears the memory (alias for the clear function)."""
|
| 69 |
-
self.clear()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
def clear_memory(self):
|
| 68 |
"""Clears the memory (alias for the clear function)."""
|
| 69 |
+
self.clear()
|
| 70 |
+
|
| 71 |
+
# Store sessions in a dictionary
|
| 72 |
+
store = {}
|
| 73 |
+
|
| 74 |
+
def get_by_session_id(session_id: str) -> EnhancedInMemoryHistory:
|
| 75 |
+
"""
|
| 76 |
+
Retrieves or creates a new memory session by session ID.
|
| 77 |
+
Parameters:
|
| 78 |
+
session_id (str): The session ID for the chat session.
|
| 79 |
+
Returns:
|
| 80 |
+
EnhancedInMemoryHistory: The memory object for the session.
|
| 81 |
+
"""
|
| 82 |
+
if session_id not in store:
|
| 83 |
+
store[session_id] = EnhancedInMemoryHistory()
|
| 84 |
+
return store[session_id]
|