feat : fast browser memory recovery

This commit is contained in:
martin legrand
2025-04-02 13:49:18 +02:00
parent aa75d276dc
commit f69ceb5025
3 changed files with 13 additions and 3 deletions
+5 -1
View File
@@ -89,7 +89,7 @@ class Memory():
def reset(self, memory: list) -> None:
self.memory = memory
def push(self, role: str, content: str) -> None:
def push(self, role: str, content: str) -> int:
"""Push a message to the memory."""
if self.memory_compression and role == 'assistant':
self.compress()
@@ -97,10 +97,14 @@ class Memory():
if self.memory[curr_idx-1]['content'] == content:
pretty_print("Warning: same message have been pushed twice to memory", color="error")
self.memory.append({'role': role, 'content': content})
return curr_idx-1
def clear(self) -> None:
self.memory = []
def clear_section(self, start: int, end: int) -> None:
self.memory = self.memory[:start] + self.memory[end:]
def get(self) -> list:
return self.memory