fix:ruff
This commit is contained in:
@@ -275,7 +275,6 @@ class SubHeartflow:
|
||||
self.gpt_instance = ResponseGenerator() # 响应生成器
|
||||
self.tool_user_instance = ToolUser() # 工具使用模块
|
||||
|
||||
|
||||
self.log_prefix = chat_manager.get_stream_name(self.subheartflow_id) or self.subheartflow_id
|
||||
|
||||
async def set_chat_state(self, new_state: "ChatState", current_states_num: tuple = ()):
|
||||
@@ -308,8 +307,7 @@ class SubHeartflow:
|
||||
|
||||
chat_stream = chat_manager.get_stream(self.chat_id)
|
||||
self.normal_chat_instance = NormalChat(
|
||||
chat_stream=chat_stream,
|
||||
interest_dict=self.get_interest_dict()
|
||||
chat_stream=chat_stream, interest_dict=self.get_interest_dict()
|
||||
)
|
||||
await self.normal_chat_instance.start_monitoring_interest()
|
||||
# NormalChat 启动/停止逻辑将在下面处理
|
||||
@@ -336,7 +334,6 @@ class SubHeartflow:
|
||||
logger.error(f"{log_prefix} 停止 NormalChat 兴趣监控时出错: {e}")
|
||||
logger.error(traceback.format_exc())
|
||||
try:
|
||||
|
||||
self.heart_fc_instance = HeartFChatting(
|
||||
chat_id=self.chat_id,
|
||||
gpt_instance=self.gpt_instance,
|
||||
@@ -394,7 +391,6 @@ class SubHeartflow:
|
||||
else:
|
||||
logger.warning(f"{log_prefix} NormalChat 实例不可用,无法管理其监控任务。")
|
||||
|
||||
|
||||
async def subheartflow_start_working(self):
|
||||
"""启动子心流的后台任务
|
||||
|
||||
@@ -410,8 +406,6 @@ class SubHeartflow:
|
||||
|
||||
logger.info(f"{self.log_prefix} 子心流后台任务已停止。")
|
||||
|
||||
|
||||
|
||||
async def do_thinking_before_reply(
|
||||
self,
|
||||
extra_info: str,
|
||||
@@ -550,6 +544,7 @@ class SubHeartflow:
|
||||
|
||||
def clear_interest_dict(self):
|
||||
self.interest_chatting.interest_dict.clear()
|
||||
|
||||
async def shutdown(self):
|
||||
"""安全地关闭子心流及其管理的任务"""
|
||||
if self.should_stop:
|
||||
|
||||
@@ -104,9 +104,11 @@ class SubHeartflowManager:
|
||||
# 设置状态为ABSENT释放资源
|
||||
if subheartflow.chat_state.chat_status != ChatState.ABSENT:
|
||||
logger.debug(f"[子心流管理] 设置 {stream_name} 状态为ABSENT")
|
||||
states_num =(self.count_subflows_by_state(ChatState.ABSENT),
|
||||
states_num = (
|
||||
self.count_subflows_by_state(ChatState.ABSENT),
|
||||
self.count_subflows_by_state(ChatState.CHAT),
|
||||
self.count_subflows_by_state(ChatState.FOCUSED))
|
||||
self.count_subflows_by_state(ChatState.FOCUSED),
|
||||
)
|
||||
await subheartflow.set_chat_state(ChatState.ABSENT, states_num)
|
||||
else:
|
||||
logger.debug(f"[子心流管理] {stream_name} 已是ABSENT状态")
|
||||
@@ -224,9 +226,11 @@ class SubHeartflowManager:
|
||||
|
||||
logger.debug(f"[激活] 正在激活子心流{stream_name}")
|
||||
|
||||
states_num =(self.count_subflows_by_state(ChatState.ABSENT),
|
||||
states_num = (
|
||||
self.count_subflows_by_state(ChatState.ABSENT),
|
||||
self.count_subflows_by_state(ChatState.CHAT),
|
||||
self.count_subflows_by_state(ChatState.FOCUSED))
|
||||
self.count_subflows_by_state(ChatState.FOCUSED),
|
||||
)
|
||||
|
||||
await flow.set_chat_state(ChatState.CHAT, states_num)
|
||||
|
||||
@@ -272,9 +276,11 @@ class SubHeartflowManager:
|
||||
should_promote = await sub_hf.should_evaluate_reply()
|
||||
if should_promote:
|
||||
logger.info(f"{log_prefix} 兴趣评估触发升级: CHAT -> FOCUSED")
|
||||
states_num =(self.count_subflows_by_state(ChatState.ABSENT),
|
||||
states_num = (
|
||||
self.count_subflows_by_state(ChatState.ABSENT),
|
||||
self.count_subflows_by_state(ChatState.CHAT),
|
||||
self.count_subflows_by_state(ChatState.FOCUSED))
|
||||
self.count_subflows_by_state(ChatState.FOCUSED),
|
||||
)
|
||||
await sub_hf.set_chat_state(ChatState.FOCUSED, states_num)
|
||||
if (
|
||||
self.subheartflows.get(flow_id)
|
||||
@@ -343,15 +349,6 @@ class SubHeartflowManager:
|
||||
else:
|
||||
logger.warning(f"尝试停用不存在的 SubHeartflow: {subheartflow_id}")
|
||||
|
||||
async def deactivate_all_subflows(self):
|
||||
"""停用并移除所有子心流。"""
|
||||
logger.info("正在停用所有 SubHeartflows...")
|
||||
# 获取当前所有 ID,避免在迭代时修改字典
|
||||
all_ids = self.get_all_subheartflows_ids()
|
||||
tasks = [self.deactivate_subflow(sub_id) for sub_id in all_ids]
|
||||
await asyncio.gather(*tasks)
|
||||
logger.info("所有 SubHeartflows 已停用。")
|
||||
|
||||
async def cleanup_inactive_subflows(self, inactive_threshold_seconds: int):
|
||||
"""清理长时间不活跃的子心流。"""
|
||||
current_time = time.time()
|
||||
|
||||
@@ -54,7 +54,6 @@ class NormalChat:
|
||||
# 改为实例方法
|
||||
async def _create_thinking_message(self, message: MessageRecv) -> str:
|
||||
"""创建思考消息"""
|
||||
userinfo = message.message_info.user_info
|
||||
messageinfo = message.message_info
|
||||
|
||||
bot_user_info = UserInfo(
|
||||
@@ -208,8 +207,6 @@ class NormalChat:
|
||||
return
|
||||
|
||||
timing_results = {}
|
||||
userinfo = message.message_info.user_info
|
||||
messageinfo = message.message_info
|
||||
|
||||
reply_probability = 1.0 if is_mentioned else 0.0 # 如果被提及,基础概率为1,否则需要意愿判断
|
||||
|
||||
|
||||
Reference in New Issue
Block a user