fix: ruff

This commit is contained in:
SengokuCola
2025-05-09 21:01:05 +08:00
parent 35b8d8ad0c
commit c7533a8160
3 changed files with 18 additions and 24 deletions

View File

@@ -110,7 +110,7 @@ class SubHeartflow:
logger.error(f"{self.log_prefix} 停止 NormalChat 监控任务时出错: {e}") logger.error(f"{self.log_prefix} 停止 NormalChat 监控任务时出错: {e}")
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
async def _start_normal_chat(self, rewind = False) -> bool: async def _start_normal_chat(self, rewind=False) -> bool:
""" """
启动 NormalChat 实例,并进行异步初始化。 启动 NormalChat 实例,并进行异步初始化。
进入 CHAT 状态时使用。 进入 CHAT 状态时使用。
@@ -128,7 +128,6 @@ class SubHeartflow:
if rewind: if rewind:
self.normal_chat_instance = NormalChat(chat_stream=chat_stream, interest_dict=self.get_interest_dict()) self.normal_chat_instance = NormalChat(chat_stream=chat_stream, interest_dict=self.get_interest_dict())
else: else:
self.normal_chat_instance = NormalChat(chat_stream=chat_stream) self.normal_chat_instance = NormalChat(chat_stream=chat_stream)
# 进行异步初始化 # 进行异步初始化

View File

@@ -249,22 +249,14 @@ class SubMind:
else: else:
# 调用记忆系统获取相关记忆 # 调用记忆系统获取相关记忆
related_memory = await HippocampusManager.get_instance().get_memory_from_topic( related_memory = await HippocampusManager.get_instance().get_memory_from_topic(
valid_keywords=filtered_keywords, valid_keywords=filtered_keywords, max_memory_num=3, max_memory_length=2, max_depth=3
max_memory_num=3,
max_memory_length=2,
max_depth=3
) )
logger.debug(f"{self.log_prefix} 获取到的记忆: {related_memory}") logger.debug(f"{self.log_prefix} 获取到的记忆: {related_memory}")
if related_memory: if related_memory:
for topic, memory in related_memory: for topic, memory in related_memory:
new_item = { new_item = {"type": "memory", "id": topic, "content": memory, "ttl": 3}
"type": "memory",
"id": topic,
"content": memory,
"ttl": 3
}
self.structured_info.append(new_item) self.structured_info.append(new_item)
logger.debug(f"{self.log_prefix} 添加新记忆: {topic} - {memory}") logger.debug(f"{self.log_prefix} 添加新记忆: {topic} - {memory}")
else: else:

View File

@@ -280,7 +280,7 @@ class SubHeartflowManager:
# --- 新增:检查是否允许进入 FOCUS 模式 --- # # --- 新增:检查是否允许进入 FOCUS 模式 --- #
if not global_config.allow_focus_mode: if not global_config.allow_focus_mode:
if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏 if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏
logger.trace(f"未开启 FOCUSED 状态 (allow_focus_mode=False)") logger.trace("未开启 FOCUSED 状态 (allow_focus_mode=False)")
return # 如果不允许,直接返回 return # 如果不允许,直接返回
# --- 结束新增 --- # --- 结束新增 ---
@@ -303,19 +303,20 @@ class SubHeartflowManager:
if sub_hf.chat_state.chat_status == ChatState.FOCUSED: if sub_hf.chat_state.chat_status == ChatState.FOCUSED:
continue continue
if sub_hf.interest_chatting.start_hfc_probability == 0: if sub_hf.interest_chatting.start_hfc_probability == 0:
continue continue
else: else:
logger.debug(f"{stream_name},现在状态: {sub_hf.chat_state.chat_status.value},进入专注概率: {sub_hf.interest_chatting.start_hfc_probability}") logger.debug(
f"{stream_name},现在状态: {sub_hf.chat_state.chat_status.value},进入专注概率: {sub_hf.interest_chatting.start_hfc_probability}"
)
# 调试用 # 调试用
from .mai_state_manager import enable_unlimited_hfc_chat from .mai_state_manager import enable_unlimited_hfc_chat
if not enable_unlimited_hfc_chat: if not enable_unlimited_hfc_chat:
if sub_hf.chat_state.chat_status != ChatState.CHAT: if sub_hf.chat_state.chat_status != ChatState.CHAT:
continue continue
if random.random() >= sub_hf.interest_chatting.start_hfc_probability: if random.random() >= sub_hf.interest_chatting.start_hfc_probability:
continue continue
@@ -416,7 +417,9 @@ class SubHeartflowManager:
chat_status_prompt = "当前没有在任何群聊中。" # 默认消息喵~ chat_status_prompt = "当前没有在任何群聊中。" # 默认消息喵~
if chat_status_lines: if chat_status_lines:
chat_status_prompt = "当前聊天情况,你已经参与了下面这几个群的聊天:\n" + "\n".join(chat_status_lines) # 拼接状态信息 chat_status_prompt = "当前聊天情况,你已经参与了下面这几个群的聊天:\n" + "\n".join(
chat_status_lines
) # 拼接状态信息
prompt = ( prompt = (
f"{prompt_personality}\n" f"{prompt_personality}\n"
@@ -526,7 +529,7 @@ class SubHeartflowManager:
# 随机判断是否退出 # 随机判断是否退出
if random.random() < exit_probability: if random.random() < exit_probability:
should_deactivate = True should_deactivate = True
reason = f"{minutes_since_last_bb:.1f}分钟未发言,触发{exit_probability*100:.0f}%退出概率" reason = f"{minutes_since_last_bb:.1f}分钟未发言,触发{exit_probability * 100:.0f}%退出概率"
except AttributeError: except AttributeError:
logger.error( logger.error(