willing基类大致完成

This commit is contained in:
meng_xi_pan
2025-04-09 12:32:18 +08:00
parent 58dc9e0840
commit b468b67cf1
4 changed files with 194 additions and 98 deletions

View File

@@ -54,7 +54,6 @@ class ReasoningChat:
)
message_manager.add_message(thinking_message)
willing_manager.change_reply_willing_sent(chat)
return thinking_id
@@ -126,7 +125,7 @@ class ReasoningChat:
)
message_manager.add_message(bot_message)
async def _update_relationship(self, message, response_set):
async def _update_relationship(self, message: MessageRecv, response_set):
"""更新关系情绪"""
ori_response = ",".join(response_set)
stance, emotion = await self.gpt._get_emotion_tags(ori_response, message.processed_plain_text)
@@ -178,7 +177,16 @@ class ReasoningChat:
# 查询缓冲器结果会整合前面跳过的消息改变processed_plain_text
buffer_result = await message_buffer.query_buffer_result(message)
# 处理提及
is_mentioned, reply_probability = is_mentioned_bot_in_message(message)
# 意愿管理器设置当前message信息
willing_manager.setup(message, chat, is_mentioned, interested_rate)
# 处理缓冲器结果
if not buffer_result:
await willing_manager.bombing_buffer_message_handle(message.message_info.message_id)
if message.message_segment.type == "text":
logger.info(f"触发缓冲,已炸飞消息:{message.processed_plain_text}")
elif message.message_segment.type == "image":
@@ -187,45 +195,21 @@ class ReasoningChat:
logger.info("触发缓冲,已炸飞消息列")
return
# 处理提及
is_mentioned, reply_probability = is_mentioned_bot_in_message(message)
# 获取回复概率
if reply_probability != 1:
reply_probability = await willing_manager.get_reply_probability(message.message_info.message_id)
# 计算回复意愿
current_willing = willing_manager.get_willing(chat_stream=chat)
willing_manager.set_willing(chat.stream_id, current_willing)
# 意愿激活
timer1 = time.time()
real_reply_probability = await willing_manager.change_reply_willing_received(
chat_stream=chat,
is_mentioned_bot=is_mentioned,
config=global_config,
is_emoji=message.is_emoji,
interested_rate=interested_rate,
sender_id=str(message.message_info.user_info.user_id),
)
if reply_probability != 1 or (groupinfo and (groupinfo.group_id not in global_config.talk_allowed_groups)):
reply_probability = real_reply_probability
timer2 = time.time()
timing_results["意愿激活"] = timer2 - timer1
# 打印消息信息
mes_name = chat.group_info.group_name if chat.group_info else "私聊"
current_time = time.strftime("%H:%M:%S", time.localtime(messageinfo.time))
logger.info(
f"[{current_time}][{mes_name}]"
f"{chat.user_info.user_nickname}:"
f"{message.processed_plain_text}[回复意愿:{current_willing:.2f}][概率:{reply_probability * 100:.1f}%]"
)
if message.message_info.additional_config:
if "maimcore_reply_probability_gain" in message.message_info.additional_config.keys():
reply_probability += message.message_info.additional_config["maimcore_reply_probability_gain"]
if message.message_info.additional_config:
if "maimcore_reply_probability_gain" in message.message_info.additional_config.keys():
reply_probability += message.message_info.additional_config["maimcore_reply_probability_gain"]
do_reply = False
if random() < reply_probability:
do_reply = True
# 回复前处理
await willing_manager.before_generate_reply_handle(message.message_info.message_id)
# 创建思考消息
timer1 = time.time()
thinking_id = await self._create_thinking_message(message, chat, userinfo, messageinfo)
@@ -260,12 +244,21 @@ class ReasoningChat:
timer2 = time.time()
timing_results["更新关系情绪"] = timer2 - timer1
# 回复后处理
await willing_manager.after_generate_reply_handle(message.message_info.message_id)
# 输出性能计时结果
if do_reply:
timing_str = " | ".join([f"{step}: {duration:.2f}" for step, duration in timing_results.items()])
trigger_msg = message.processed_plain_text
response_msg = " ".join(response_set) if response_set else "无回复"
logger.info(f"触发消息: {trigger_msg[:20]}... | 推理消息: {response_msg[:20]}... | 性能计时: {timing_str}")
else:
# 不回复处理
await willing_manager.not_reply_handle(message.message_info.message_id)
# 意愿管理器注销当前message信息
willing_manager.delete(message.message_info.message_id)
def _check_ban_words(self, text: str, chat, userinfo) -> bool:
"""检查消息中是否包含过滤词"""