feat : fix displaying problem + memory compression on loading + personality prompt + technical image
This commit is contained in:
+9
-7
@@ -9,7 +9,7 @@ import json
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from sources.utility import timer_decorator
|
||||
from sources.utility import timer_decorator, pretty_print
|
||||
|
||||
class Memory():
|
||||
"""
|
||||
@@ -33,9 +33,8 @@ class Memory():
|
||||
self.model = "pszemraj/led-base-book-summary"
|
||||
self.device = self.get_cuda_device()
|
||||
self.memory_compression = memory_compression
|
||||
if memory_compression:
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(self.model)
|
||||
self.model = AutoModelForSeq2SeqLM.from_pretrained(self.model)
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(self.model)
|
||||
self.model = AutoModelForSeq2SeqLM.from_pretrained(self.model)
|
||||
|
||||
def get_filename(self) -> str:
|
||||
return f"memory_{self.session_time.strftime('%Y-%m-%d_%H-%M-%S')}.txt"
|
||||
@@ -78,6 +77,9 @@ class Memory():
|
||||
path = os.path.join(save_path, filename)
|
||||
with open(path, 'r') as f:
|
||||
self.memory = json.load(f)
|
||||
if self.memory[-1]['role'] == 'user':
|
||||
self.memory.pop()
|
||||
self.compress()
|
||||
|
||||
def reset(self, memory: list) -> None:
|
||||
self.memory = memory
|
||||
@@ -86,7 +88,9 @@ class Memory():
|
||||
"""Push a message to the memory."""
|
||||
if self.memory_compression and role == 'assistant':
|
||||
self.compress()
|
||||
# we don't compress the last message
|
||||
curr_idx = len(self.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})
|
||||
|
||||
def clear(self) -> None:
|
||||
@@ -134,8 +138,6 @@ class Memory():
|
||||
"""
|
||||
Compress the memory using the AI model.
|
||||
"""
|
||||
if not self.memory_compression:
|
||||
return
|
||||
for i in range(len(self.memory)):
|
||||
if i < 3:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user