超级Ruff
This commit is contained in:
@@ -63,5 +63,4 @@ class CoreActionsPlugin(BasePlugin):
|
||||
if self.get_config("components.enable_emoji", True):
|
||||
components.append((EmojiAction.get_action_info(), EmojiAction))
|
||||
|
||||
|
||||
return components
|
||||
|
||||
@@ -74,7 +74,9 @@ class BuildMemoryAction(BaseAction):
|
||||
|
||||
# 动作基本信息
|
||||
action_name = "build_memory"
|
||||
action_description = "了解对于某个概念或者某件事的记忆,并存储下来,在之后的聊天中,你可以根据这条记忆来获取相关信息"
|
||||
action_description = (
|
||||
"了解对于某个概念或者某件事的记忆,并存储下来,在之后的聊天中,你可以根据这条记忆来获取相关信息"
|
||||
)
|
||||
|
||||
# 动作参数定义
|
||||
action_parameters = {
|
||||
@@ -103,31 +105,34 @@ class BuildMemoryAction(BaseAction):
|
||||
concept_name = self.action_data.get("concept_name", "")
|
||||
# 2. 获取目标用户信息
|
||||
|
||||
|
||||
|
||||
# 对 concept_name 进行jieba分词
|
||||
concept_name_tokens = cut_key_words(concept_name)
|
||||
# logger.info(f"{self.log_prefix} 对 concept_name 进行分词结果: {concept_name_tokens}")
|
||||
|
||||
|
||||
filtered_concept_name_tokens = [
|
||||
token for token in concept_name_tokens if all(keyword not in token for keyword in global_config.memory.memory_ban_words)
|
||||
token
|
||||
for token in concept_name_tokens
|
||||
if all(keyword not in token for keyword in global_config.memory.memory_ban_words)
|
||||
]
|
||||
|
||||
|
||||
if not filtered_concept_name_tokens:
|
||||
logger.warning(f"{self.log_prefix} 过滤后的概念名称列表为空,跳过添加记忆")
|
||||
return False, "过滤后的概念名称列表为空,跳过添加记忆"
|
||||
|
||||
similar_topics_dict = hippocampus_manager.get_hippocampus().parahippocampal_gyrus.get_similar_topics_from_keywords(filtered_concept_name_tokens)
|
||||
await hippocampus_manager.get_hippocampus().parahippocampal_gyrus.add_memory_with_similar(concept_description, similar_topics_dict)
|
||||
|
||||
|
||||
|
||||
|
||||
similar_topics_dict = (
|
||||
hippocampus_manager.get_hippocampus().parahippocampal_gyrus.get_similar_topics_from_keywords(
|
||||
filtered_concept_name_tokens
|
||||
)
|
||||
)
|
||||
await hippocampus_manager.get_hippocampus().parahippocampal_gyrus.add_memory_with_similar(
|
||||
concept_description, similar_topics_dict
|
||||
)
|
||||
|
||||
return True, f"成功添加记忆: {concept_name}"
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 构建记忆时出错: {e}")
|
||||
return False, f"构建记忆时出错: {e}"
|
||||
|
||||
|
||||
|
||||
# 还缺一个关系的太多遗忘和对应的提取
|
||||
|
||||
@@ -425,7 +425,7 @@ class ManagementCommand(BaseCommand):
|
||||
await self._send_message(f"本地禁用组件成功: {component_name}")
|
||||
else:
|
||||
await self._send_message(f"本地禁用组件失败: {component_name}")
|
||||
|
||||
|
||||
async def _send_message(self, message: str):
|
||||
await send_api.text_to_stream(message, self.stream_id, typing=False, storage_message=False)
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class BuildRelationAction(BaseAction):
|
||||
if not person.is_known:
|
||||
logger.warning(f"{self.log_prefix} 用户 {person_name} 不存在,跳过添加记忆")
|
||||
return False, f"用户 {person_name} 不存在,跳过添加记忆"
|
||||
|
||||
|
||||
person.last_know = time.time()
|
||||
person.know_times += 1
|
||||
person.sync_to_database()
|
||||
@@ -178,7 +178,9 @@ class BuildRelationAction(BaseAction):
|
||||
|
||||
chat_model_config = models.get("utils")
|
||||
success, update_memory, _, _ = await llm_api.generate_with_model(
|
||||
prompt, model_config=chat_model_config, request_type="relation.category.update" # type: ignore
|
||||
prompt,
|
||||
model_config=chat_model_config,
|
||||
request_type="relation.category.update", # type: ignore
|
||||
)
|
||||
|
||||
update_memory_data = json.loads(repair_json(update_memory))
|
||||
@@ -190,7 +192,7 @@ class BuildRelationAction(BaseAction):
|
||||
# 新记忆
|
||||
person.memory_points.append(f"{category}:{new_memory}:1.0")
|
||||
person.sync_to_database()
|
||||
|
||||
|
||||
logger.info(f"{self.log_prefix} 为{person.person_name}新增记忆点: {new_memory}")
|
||||
|
||||
return True, f"为{person.person_name}新增记忆点: {new_memory}"
|
||||
@@ -207,14 +209,15 @@ class BuildRelationAction(BaseAction):
|
||||
person.memory_points.append(f"{category}:{integrate_memory}:{memory_weight + 1.0}")
|
||||
person.sync_to_database()
|
||||
|
||||
logger.info(f"{self.log_prefix} 更新{person.person_name}的记忆点: {memory_content} -> {integrate_memory}")
|
||||
logger.info(
|
||||
f"{self.log_prefix} 更新{person.person_name}的记忆点: {memory_content} -> {integrate_memory}"
|
||||
)
|
||||
|
||||
return True, f"更新{person.person_name}的记忆点: {memory_content} -> {integrate_memory}"
|
||||
|
||||
else:
|
||||
logger.warning(f"{self.log_prefix} 删除记忆点失败: {memory_content}")
|
||||
return False, f"删除{person.person_name}的记忆点失败: {memory_content}"
|
||||
|
||||
|
||||
return True, "关系动作执行成功"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user