fix: 兴趣消息恢复改为并发
This commit is contained in:
@@ -225,9 +225,9 @@ class MessageManager:
|
||||
if (
|
||||
# message.apply_set_reply_logic # 检查标记
|
||||
# and message.is_head
|
||||
message.is_head
|
||||
and (thinking_messages_count > 3 or thinking_messages_length > 200)
|
||||
and not message.is_private_message()
|
||||
# message.is_head
|
||||
# and (thinking_messages_count > 3 or thinking_messages_length > 200) and
|
||||
not message.is_private_message()
|
||||
):
|
||||
logger.debug(
|
||||
f"[{message.chat_stream.stream_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}..."
|
||||
|
||||
@@ -211,8 +211,9 @@ class NormalChat:
|
||||
if not items_to_process:
|
||||
continue
|
||||
|
||||
# 处理每条兴趣消息
|
||||
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
|
||||
# 并行处理兴趣消息
|
||||
async def process_single_message(msg_id, message, interest_value, is_mentioned):
|
||||
"""处理单个兴趣消息"""
|
||||
try:
|
||||
# 处理消息
|
||||
if time.time() - self.start_time > 300:
|
||||
@@ -230,6 +231,24 @@ class NormalChat:
|
||||
finally:
|
||||
self.interest_dict.pop(msg_id, None)
|
||||
|
||||
# 创建并行任务列表
|
||||
tasks = []
|
||||
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
|
||||
task = process_single_message(msg_id, message, interest_value, is_mentioned)
|
||||
tasks.append(task)
|
||||
|
||||
# 并行执行所有任务,限制并发数量避免资源过度消耗
|
||||
if tasks:
|
||||
# 使用信号量控制并发数,最多同时处理5个消息
|
||||
semaphore = asyncio.Semaphore(5)
|
||||
|
||||
async def limited_process(task):
|
||||
async with semaphore:
|
||||
await task
|
||||
|
||||
limited_tasks = [limited_process(task) for task in tasks]
|
||||
await asyncio.gather(*limited_tasks, return_exceptions=True)
|
||||
|
||||
# 改为实例方法, 移除 chat 参数
|
||||
async def normal_response(self, message: MessageRecv, is_mentioned: bool, interested_rate: float) -> None:
|
||||
# 新增:如果已停用,直接返回
|
||||
@@ -238,7 +257,9 @@ class NormalChat:
|
||||
return
|
||||
|
||||
timing_results = {}
|
||||
reply_probability = 1.0 if is_mentioned and global_config.normal_chat.mentioned_bot_inevitable_reply else 0.0 # 如果被提及,且开启了提及必回复,则基础概率为1,否则需要意愿判断
|
||||
reply_probability = (
|
||||
1.0 if is_mentioned and global_config.normal_chat.mentioned_bot_inevitable_reply else 0.0
|
||||
) # 如果被提及,且开启了提及必回复,则基础概率为1,否则需要意愿判断
|
||||
|
||||
# 意愿管理器:设置当前message信息
|
||||
willing_manager.setup(message, self.chat_stream, is_mentioned, interested_rate)
|
||||
|
||||
Reference in New Issue
Block a user