初始化记忆模块

This commit is contained in:
玄凤科技 2025-03-06 16:38:16 +08:00
parent 1569d7ba64
commit ef29877699
3 changed files with 6 additions and 6 deletions

View file

@ -101,8 +101,7 @@ class ConnectionHandler:
await self.auth.authenticate(self.headers) await self.auth.authenticate(self.headers)
device_id = self.headers.get("device-id", None) device_id = self.headers.get("device-id", None)
self.memory.set_role_id(device_id) self.memory.init_memory(device_id, self.llm)
self.memory.set_llm(self.llm)
# Load private configuration if device_id is provided # Load private configuration if device_id is provided
bUsePrivateConfig = self.config.get("use_private_config", False) bUsePrivateConfig = self.config.get("use_private_config", False)

View file

@ -20,9 +20,6 @@ class MemoryProviderBase(ABC):
"""Query memories for specific role based on similarity""" """Query memories for specific role based on similarity"""
return "please implement query method" return "please implement query method"
def set_role_id(self, role_id: str): def init_memory(self, role_id, llm):
self.role_id = role_id self.role_id = role_id
def set_llm(self, llm):
self.llm = llm self.llm = llm
logger.bind(tag=TAG).debug("Set LLM for memory provider")

View file

@ -95,6 +95,10 @@ class MemoryProvider(MemoryProviderBase):
self.memory_path = get_project_dir() + 'data/.memory.yaml' self.memory_path = get_project_dir() + 'data/.memory.yaml'
self.load_memory() self.load_memory()
def init_memory(self, role_id, llm):
super().init_memory(role_id, llm)
self.load_memory()
def load_memory(self): def load_memory(self):
all_memory = {} all_memory = {}
if os.path.exists(self.memory_path): if os.path.exists(self.memory_path):