Skip to content

Commit

Permalink
Merge pull request #80 from codefuse-ai/memory_dev2
Browse files Browse the repository at this point in the history
new memory func
  • Loading branch information
LewisLiu-code authored Nov 14, 2024
2 parents 85221a3 + 6bd140d commit 80a5277
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 45 additions & 1 deletion muagent/connector/memory_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,48 @@ def tbasedoc2Memory(self, r_docs) -> Memory:
# content = message.customed_kargs.pop(key)
# if content is not None:
# message.setattr(key, content)
return memory
return memory


def init_global_msg(self, chat_index: str, role_name: str, role_content: str, role_type: str = "global_value") -> bool:
msg = Message(chat_index=chat_index, message_index = role_name ,role_name=role_name, role_type=role_type, role_content=role_content)
try:
self.append(msg)
return True
except Exception as e:
logger.error(f"Failed to initialize global message: {e}")
return False

def get_msg_by_role_name(self, chat_index: str, role_name: str) -> Optional[Message]:
memory = self.get_memory_pool_by_all({"chat_index": chat_index, "role_name": role_name})
# memory = self.get_memory_pool(chat_index)
for msg in memory.messages:
if msg.role_name == role_name:
return msg
return None

def get_msg_content_by_role_name(self, chat_index: str, role_name: str) -> Optional[str]:
message = self.get_msg_by_role_name(chat_index, role_name)
if message == None:
return None
else:
return message.role_content

def update_msg_content_by_rule(self, chat_index: str, role_name: str, new_content: str,update_rule: str) -> bool:
message = self.get_msg_by_role_name(chat_index, role_name)

if message == None:
return False

prompt = f"{new_content}\n{role_name}:{message.role_content}\n{update_rule}"

model = getChatModelFromConfig(self.llm_config)

new_role_content = model.predict(prompt)

if new_role_content is not None:
message.role_content = new_role_content
self.append(message)
return True
else:
return False
6 changes: 4 additions & 2 deletions muagent/db_handler/graph_db_handler/nebula_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def execute_cypher(self, cypher: str, space_name: str = '',ignore_log: bool = Fa
if ignore_log == False:
if resp.is_succeeded():
#logger.info(f"Successfully executed Cypher query: {cypher}")

pass

else:
Expand Down Expand Up @@ -291,9 +292,10 @@ def add_node(self, node: GNode) -> GbaseExecStatus:
value = value.replace("\n", "\\n").replace("\"", "\\\"")
cypher += f'"{value}",'
elif prop_name == 'description':
# 特殊符号需要手动加\转义符
value = value.replace("\n", "\\n").replace("\"", "\\\"")
# logger.info(value)
cypher += f'"{value}",'
elif prop_name == 'envdescription':
value = value.replace("\n", "\\n").replace("\"", "\\\"")
cypher += f'"{value}",'
else:
cypher += f'"{value}",'
Expand Down

0 comments on commit 80a5277

Please sign in to comment.