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(traceback.format_exc())
async def _start_normal_chat(self, rewind = False) -> bool:
async def _start_normal_chat(self, rewind=False) -> bool:
"""
启动 NormalChat 实例,并进行异步初始化。
进入 CHAT 状态时使用。
@@ -128,7 +128,6 @@ class SubHeartflow:
if rewind:
self.normal_chat_instance = NormalChat(chat_stream=chat_stream, interest_dict=self.get_interest_dict())
else:
self.normal_chat_instance = NormalChat(chat_stream=chat_stream)
# 进行异步初始化
@@ -252,7 +251,7 @@ class SubHeartflow:
elif new_state == ChatState.ABSENT:
logger.info(f"{log_prefix} 进入 ABSENT 状态,停止所有聊天活动...")
await self.clear_interest_dict()
await self._stop_normal_chat()
await self._stop_heart_fc_chat()
state_changed = True # 总是可以成功转换到 ABSENT

View File

@@ -233,7 +233,7 @@ class SubMind:
keywords = [word for word in chat_words if len(word) > 1]
# 去重并限制数量
keywords = list(set(keywords))[:5]
logger.debug(f"{self.log_prefix} 提取的关键词: {keywords}")
# 检查已有记忆,过滤掉已存在的主题
existing_topics = set()
@@ -243,28 +243,20 @@ class SubMind:
# 过滤掉已存在的主题
filtered_keywords = [k for k in keywords if k not in existing_topics]
if not filtered_keywords:
logger.debug(f"{self.log_prefix} 所有关键词对应的记忆都已存在,跳过记忆提取")
else:
# 调用记忆系统获取相关记忆
related_memory = await HippocampusManager.get_instance().get_memory_from_topic(
valid_keywords=filtered_keywords,
max_memory_num=3,
max_memory_length=2,
max_depth=3
valid_keywords=filtered_keywords, max_memory_num=3, max_memory_length=2, max_depth=3
)
logger.debug(f"{self.log_prefix} 获取到的记忆: {related_memory}")
if related_memory:
for topic, memory in related_memory:
new_item = {
"type": "memory",
"id": topic,
"content": memory,
"ttl": 3
}
new_item = {"type": "memory", "id": topic, "content": memory, "ttl": 3}
self.structured_info.append(new_item)
logger.debug(f"{self.log_prefix} 添加新记忆: {topic} - {memory}")
else:

View File

@@ -280,7 +280,7 @@ class SubHeartflowManager:
# --- 新增:检查是否允许进入 FOCUS 模式 --- #
if not global_config.allow_focus_mode:
if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏
logger.trace(f"未开启 FOCUSED 状态 (allow_focus_mode=False)")
logger.trace("未开启 FOCUSED 状态 (allow_focus_mode=False)")
return # 如果不允许,直接返回
# --- 结束新增 ---
@@ -298,24 +298,25 @@ class SubHeartflowManager:
for sub_hf in list(self.subheartflows.values()):
flow_id = sub_hf.subheartflow_id
stream_name = chat_manager.get_stream_name(flow_id) or flow_id
# 跳过非CHAT状态或已经是FOCUSED状态的子心流
if sub_hf.chat_state.chat_status == ChatState.FOCUSED:
continue
if sub_hf.interest_chatting.start_hfc_probability == 0:
continue
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
if not enable_unlimited_hfc_chat:
if sub_hf.chat_state.chat_status != ChatState.CHAT:
continue
if random.random() >= sub_hf.interest_chatting.start_hfc_probability:
continue
@@ -416,7 +417,9 @@ class SubHeartflowManager:
chat_status_prompt = "当前没有在任何群聊中。" # 默认消息喵~
if chat_status_lines:
chat_status_prompt = "当前聊天情况,你已经参与了下面这几个群的聊天:\n" + "\n".join(chat_status_lines) # 拼接状态信息
chat_status_prompt = "当前聊天情况,你已经参与了下面这几个群的聊天:\n" + "\n".join(
chat_status_lines
) # 拼接状态信息
prompt = (
f"{prompt_personality}\n"
@@ -526,7 +529,7 @@ class SubHeartflowManager:
# 随机判断是否退出
if random.random() < exit_probability:
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:
logger.error(