Revert "feat(reminder): 增强定时提醒系统,实现智能用户识别与上下文感知回复"
This reverts commit e1ebf41f8d.
This commit is contained in:
committed by
Windpicker-owo
parent
38c94ecb73
commit
5eaa5f74e8
@@ -139,6 +139,21 @@ class ProactiveThinker:
|
||||
logger.error(f"{self.context.log_prefix} 主动思考执行异常: {e}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
async def _get_reminder_context(self, message_id: str) -> str:
|
||||
"""获取提醒消息的上下文"""
|
||||
try:
|
||||
# 只获取那一条消息
|
||||
message_record = await db_get(Messages, {"message_id": message_id}, single_result=True)
|
||||
if message_record:
|
||||
# 使用 build_readable_messages_with_id 来格式化单条消息
|
||||
chat_context_block, _ = build_readable_messages_with_id(messages=[message_record])
|
||||
return chat_context_block
|
||||
return "无法加载相关的聊天记录。"
|
||||
except Exception as e:
|
||||
logger.error(f"{self.context.log_prefix} 获取提醒上下文失败: {e}")
|
||||
return "无法加载相关的聊天记录。"
|
||||
|
||||
|
||||
async def _generate_proactive_content_and_send(self, action_result: Dict[str, Any], trigger_event: ProactiveTriggerEvent):
|
||||
"""
|
||||
获取实时信息,构建最终的生成提示词,并生成和发送主动回复。
|
||||
|
||||
@@ -69,49 +69,15 @@ class AtAction(BaseAction):
|
||||
if not member_list:
|
||||
return False, "群成员列表为空"
|
||||
|
||||
# 优化用户匹配逻辑
|
||||
best_match = None
|
||||
user_id = None
|
||||
# 使用模糊匹配找到最接近的用户名
|
||||
choices = {member["card"] or member["nickname"]: member["user_id"] for member in member_list}
|
||||
best_match, score = process.extractOne(user_name, choices.keys())
|
||||
|
||||
# 1. 完全精确匹配
|
||||
for member in member_list:
|
||||
card = member.get("card", "")
|
||||
nickname = member.get("nickname", "")
|
||||
if user_name == card or user_name == nickname:
|
||||
best_match = card if user_name == card else nickname
|
||||
user_id = member["user_id"]
|
||||
logger.info(f"找到完全精确匹配: '{user_name}' -> '{best_match}' (ID: {user_id})")
|
||||
break
|
||||
|
||||
# 2. 包含关系匹配
|
||||
if not best_match:
|
||||
containing_matches = []
|
||||
for member in member_list:
|
||||
card = member.get("card", "")
|
||||
nickname = member.get("nickname", "")
|
||||
if user_name in card:
|
||||
containing_matches.append((card, member["user_id"]))
|
||||
elif user_name in nickname:
|
||||
containing_matches.append((nickname, member["user_id"]))
|
||||
|
||||
if containing_matches:
|
||||
# 选择最短的匹配项,因为通常更精确
|
||||
best_match, user_id = min(containing_matches, key=lambda x: len(x[0]))
|
||||
logger.info(f"找到包含关系匹配: '{user_name}' -> '{best_match}' (ID: {user_id})")
|
||||
|
||||
# 3. 模糊匹配作为兜底
|
||||
if not best_match:
|
||||
choices = {member["card"] or member["nickname"]: member["user_id"] for member in member_list}
|
||||
fuzzy_match, score = process.extractOne(user_name, choices.keys())
|
||||
if score >= 60: # 维持较高的阈值
|
||||
best_match = fuzzy_match
|
||||
user_id = choices[best_match]
|
||||
logger.info(f"找到模糊匹配: '{user_name}' -> '{best_match}' (ID: {user_id}, Score: {score})")
|
||||
|
||||
if not best_match:
|
||||
logger.warning(f"所有匹配策略都未能找到用户: '{user_name}'")
|
||||
if score < 30: # 设置一个匹配度阈值
|
||||
logger.info(f"找不到与 '{user_name}' 高度匹配的用户 (最佳匹配: {best_match}, 分数: {score})")
|
||||
return False, "用户不存在"
|
||||
|
||||
user_id = choices[best_match]
|
||||
user_info = {"user_id": user_id, "user_nickname": best_match}
|
||||
|
||||
try:
|
||||
@@ -126,23 +92,13 @@ class AtAction(BaseAction):
|
||||
return False, "聊天流不存在"
|
||||
|
||||
replyer = DefaultReplyer(chat_stream)
|
||||
# 优化提示词,消除记忆割裂感
|
||||
reminder_task = at_message.replace("定时提醒:", "").strip()
|
||||
extra_info = f"""你之前记下了一个提醒任务:'{reminder_task}'
|
||||
现在时间到了,你需要去提醒用户 '{user_name}'。
|
||||
|
||||
**重要规则**:
|
||||
- 你的任务**只**是生成提醒的**内容**。
|
||||
- **绝对不要**在你的回复中包含任何`@`符号或者目标用户的名字。真正的@操作会由系统自动完成。
|
||||
- 像一个朋友一样,自然地完成这个提醒,而不是生硬地复述任务。
|
||||
|
||||
请直接输出提醒的**内容**。"""
|
||||
extra_info = f"你需要艾特用户 {user_name} 并回复他们说: {at_message}"
|
||||
|
||||
success, llm_response, _ = await replyer.generate_reply_with_context(
|
||||
reply_to=f"是时候提醒'{user_name}'了", # 内部上下文,更符合执行任务的语境
|
||||
reply_to=f"{user_name}:{at_message}",
|
||||
extra_info=extra_info,
|
||||
enable_tool=False,
|
||||
from_plugin=True # 标记为插件调用,以便LLM更好地理解上下文
|
||||
from_plugin=False
|
||||
)
|
||||
|
||||
if not success or not llm_response:
|
||||
|
||||
Reference in New Issue
Block a user