mirror of https://github.com/Mai-with-u/MaiBot.git
feat:优化replyer表现
parent
9a5028484d
commit
8cd55af68a
|
|
@ -3,12 +3,13 @@
|
|||
|
||||
## [0.10.2] - 2025-8-31
|
||||
### 🌟 主要功能更改
|
||||
- 精简了人格相关配置,提供更清晰,有效的自定义
|
||||
- 大幅优化了聊天逻辑,更易配置,动态控制
|
||||
- 记忆系统重新启用,更好更优秀
|
||||
- 更好的event系统
|
||||
- 现在支持提及100%回复
|
||||
|
||||
### 细节功能更改
|
||||
- 更好的event系统
|
||||
- 记忆系统优化
|
||||
- 为空回复添加重试机制
|
||||
- 修复tts插件可能的复读问题
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ def init_prompt():
|
|||
请你根据聊天内容和用户的最新消息选择合适回复或者沉默:
|
||||
1.你可以选择呼叫了你的名字,但是你没有做出回应的消息进行回复
|
||||
2.你可以自然的顺着正在进行的聊天内容进行回复或自然的提出一个问题
|
||||
3.你的兴趣是:{interest}
|
||||
4.如果你刚刚进行了回复,不要对同一个话题重复回应
|
||||
5.请控制你的发言频率,不要太过频繁的发言,当你刚刚发送了消息,没有人回复时,选择no_action
|
||||
6.如果有人对你感到厌烦,请减少回复
|
||||
|
|
@ -92,8 +93,8 @@ def init_prompt():
|
|||
**回复标准**
|
||||
请你选择合适的消息进行回复:
|
||||
1.你可以选择呼叫了你的名字,但是你没有做出回应的消息进行回复
|
||||
2.你可以自然的顺着正在进行的聊天内容进行回复
|
||||
3.你可以自然的提出一个问题
|
||||
2.你可以自然的顺着正在进行的聊天内容进行回复,或者自然的提出一个问题
|
||||
3.你的兴趣是{interest}
|
||||
4.如果有人对你感到厌烦,请你不要太积极的提问或是表达,可以进行顺从
|
||||
5.如果有人对你进行攻击,或者情绪激动,请你以合适的方法应对
|
||||
6.最好不要选择图片和表情包作为回复对象
|
||||
|
|
@ -597,6 +598,7 @@ class ActionPlanner:
|
|||
chat_content_block=chat_content_block,
|
||||
# actions_before_now_block=actions_before_now_block,
|
||||
message_id_list=message_id_list,
|
||||
interest=global_config.personality.interest,
|
||||
)
|
||||
|
||||
# --- 调用 LLM (普通文本生成) ---
|
||||
|
|
@ -757,6 +759,7 @@ class ActionPlanner:
|
|||
mode: ChatMode = ChatMode.FOCUS,
|
||||
# actions_before_now_block :str = "",
|
||||
chat_content_block: str = "",
|
||||
interest: str = "",
|
||||
) -> tuple[str, List[Tuple[str, "DatabaseMessages"]]]: # sourcery skip: use-join
|
||||
"""构建 Planner LLM 的提示词 (获取模板并填充数据)"""
|
||||
try:
|
||||
|
|
@ -834,6 +837,7 @@ class ActionPlanner:
|
|||
# action_options_text=action_options_block,
|
||||
moderation_prompt=moderation_prompt_block,
|
||||
name_block=name_block,
|
||||
interest=interest,
|
||||
)
|
||||
else:
|
||||
planner_prompt_template = await global_prompt_manager.get_prompt_async("planner_reply_prompt")
|
||||
|
|
@ -844,6 +848,7 @@ class ActionPlanner:
|
|||
moderation_prompt=moderation_prompt_block,
|
||||
name_block=name_block,
|
||||
actions_before_now_block=actions_before_now_block,
|
||||
interest=interest,
|
||||
)
|
||||
return prompt, message_id_list
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -51,11 +51,14 @@ def init_prompt():
|
|||
{chat_info}
|
||||
{identity}
|
||||
|
||||
你正在{chat_target_2},{reply_target_block}
|
||||
对这句话,你想表达,原句:{raw_reply},原因是:{reason}。你现在要思考怎么组织回复
|
||||
你现在的心情是:{mood_state}
|
||||
你正在{chat_target_2},{reply_target_block}
|
||||
你想要对上述的发言进行回复,回复的具体内容(原句)是:{raw_reply}
|
||||
原因是:{reason}
|
||||
现在请你将这条具体内容改写成一条适合在群聊中发送的回复消息。
|
||||
你需要使用合适的语法和句法,参考聊天内容,组织一条日常且口语化的回复。请你修改你想表达的原句,符合你的表达风格和语言习惯
|
||||
{reply_style},你可以完全重组回复,保留最基本的表达含义就好,但重组后保持语意通顺。
|
||||
{reply_style}
|
||||
你可以完全重组回复,保留最基本的表达含义就好,但重组后保持语意通顺。
|
||||
{keywords_reaction_prompt}
|
||||
{moderation_prompt}
|
||||
不要输出多余内容(包括前后缀,冒号和引号,括号,表情包,emoji,at或 @等 ),只输出一条回复就好。
|
||||
|
|
@ -66,44 +69,39 @@ def init_prompt():
|
|||
|
||||
# s4u 风格的 prompt 模板
|
||||
Prompt(
|
||||
"""
|
||||
{expression_habits_block}{tool_info_block}
|
||||
{knowledge_prompt}{memory_block}{relation_info_block}
|
||||
{extra_info_block}
|
||||
{identity}
|
||||
{action_descriptions}
|
||||
{time_block}
|
||||
你现在的主要任务是和 {sender_name} 聊天。同时,也有其他用户会参与聊天,你可以参考他们的回复内容,但是你现在想回复{sender_name}的发言。
|
||||
"""{identity}
|
||||
你正在群聊中聊天,你想要回复 {sender_name} 的发言。同时,也有其他用户会参与聊天,你可以参考他们的回复内容,但是你现在想回复{sender_name}的发言。
|
||||
|
||||
{time_block}
|
||||
{background_dialogue_prompt}
|
||||
{core_dialogue_prompt}
|
||||
|
||||
{expression_habits_block}{tool_info_block}
|
||||
{knowledge_prompt}{memory_block}{relation_info_block}
|
||||
{extra_info_block}
|
||||
|
||||
{reply_target_block}
|
||||
|
||||
|
||||
你现在的心情是:{mood_state}
|
||||
你的心情:{mood_state}
|
||||
{reply_style}
|
||||
注意不要复读你说过的话
|
||||
{keywords_reaction_prompt}
|
||||
请注意不要输出多余内容(包括前后缀,冒号和引号,at或 @等 )。只输出回复内容。
|
||||
{moderation_prompt}
|
||||
不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,emoji,at或 @等 )。只输出一条回复就好
|
||||
现在,你说:
|
||||
""",
|
||||
现在,你说:""",
|
||||
"replyer_prompt",
|
||||
)
|
||||
|
||||
Prompt(
|
||||
"""
|
||||
{expression_habits_block}{tool_info_block}
|
||||
{knowledge_prompt}{memory_block}{relation_info_block}
|
||||
{extra_info_block}
|
||||
{identity}
|
||||
{action_descriptions}
|
||||
"""{identity}
|
||||
{time_block}
|
||||
你现在正在一个QQ群里聊天,以下是正在进行的聊天内容:
|
||||
{background_dialogue_prompt}
|
||||
|
||||
{expression_habits_block}{tool_info_block}
|
||||
{knowledge_prompt}{memory_block}{relation_info_block}
|
||||
{extra_info_block}
|
||||
|
||||
你现在想补充说明你刚刚自己的发言内容:{target},原因是{reason}
|
||||
请你根据聊天内容,组织一条新回复。注意,{target} 是刚刚你自己的发言,你要在这基础上进一步发言,请按照你自己的角度来继续进行回复。
|
||||
注意保持上下文的连贯性。
|
||||
|
|
@ -638,9 +636,12 @@ class DefaultReplyer:
|
|||
"""构建动作提示"""
|
||||
|
||||
action_descriptions = ""
|
||||
skip_names = ["emoji","build_memory","build_relation","reply"]
|
||||
if available_actions:
|
||||
action_descriptions = "除了进行回复之外,你可以做以下这些动作,不过这些动作由另一个模型决定,:\n"
|
||||
for action_name, action_info in available_actions.items():
|
||||
if action_name in skip_names:
|
||||
continue
|
||||
action_description = action_info.description
|
||||
action_descriptions += f"- {action_name}: {action_description}\n"
|
||||
action_descriptions += "\n"
|
||||
|
|
@ -649,7 +650,7 @@ class DefaultReplyer:
|
|||
if chosen_actions_info:
|
||||
for action_plan_info in chosen_actions_info:
|
||||
action_name = action_plan_info.action_type
|
||||
if action_name == "reply":
|
||||
if action_name in skip_names:
|
||||
continue
|
||||
action_description: str = "无描述"
|
||||
reasoning: str = "无原因"
|
||||
|
|
@ -679,12 +680,12 @@ class DefaultReplyer:
|
|||
|
||||
async def build_prompt_reply_context(
|
||||
self,
|
||||
reply_message: DatabaseMessages,
|
||||
extra_info: str = "",
|
||||
reply_reason: str = "",
|
||||
available_actions: Optional[Dict[str, ActionInfo]] = None,
|
||||
chosen_actions: Optional[List[ActionPlannerInfo]] = None,
|
||||
enable_tool: bool = True,
|
||||
reply_message: Optional[DatabaseMessages] = None,
|
||||
) -> Tuple[str, List[int]]:
|
||||
"""
|
||||
构建回复器上下文
|
||||
|
|
@ -725,6 +726,7 @@ class DefaultReplyer:
|
|||
mood_prompt = chat_mood.mood_state
|
||||
|
||||
target = replace_user_references(target, chat_stream.platform, replace_bot_name=True)
|
||||
target = re.sub(r"\\[picid:[^\\]]+\\]", "[图片]", target)
|
||||
|
||||
message_list_before_now_long = get_raw_msg_before_timestamp_with_chat(
|
||||
chat_id=chat_id,
|
||||
|
|
@ -809,6 +811,11 @@ class DefaultReplyer:
|
|||
|
||||
moderation_prompt_block = "请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if sender:
|
||||
if is_group_chat:
|
||||
reply_target_block = (
|
||||
|
|
@ -879,6 +886,8 @@ class DefaultReplyer:
|
|||
is_group_chat = bool(chat_stream.group_info)
|
||||
|
||||
sender, target = self._parse_reply_target(reply_to)
|
||||
target = replace_user_references(target, chat_stream.platform, replace_bot_name=True)
|
||||
target = re.sub(r"\\[picid:[^\\]]+\\]", "[图片]", target)
|
||||
|
||||
# 添加情绪状态获取
|
||||
if global_config.mood.enable_mood:
|
||||
|
|
@ -1008,6 +1017,8 @@ class DefaultReplyer:
|
|||
# 直接使用已初始化的模型实例
|
||||
logger.info(f"使用模型集生成回复: {', '.join(map(str, self.express_model.model_for_task.model_list))}")
|
||||
|
||||
logger.info(f"\n{prompt}\n")
|
||||
|
||||
if global_config.debug.show_prompt:
|
||||
logger.info(f"\n{prompt}\n")
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
import time
|
||||
from typing import List, Dict, Any, Tuple, Optional
|
||||
from src.common.data_models.database_data_model import DatabaseMessages
|
||||
from src.common.database.database_model import Images
|
||||
from src.config.config import global_config
|
||||
from src.chat.utils.chat_message_builder import (
|
||||
get_raw_msg_by_timestamp,
|
||||
|
|
@ -488,3 +489,15 @@ def filter_mai_messages(messages: List[DatabaseMessages]) -> List[DatabaseMessag
|
|||
过滤后的消息列表
|
||||
"""
|
||||
return [msg for msg in messages if msg.user_info.user_id != str(global_config.bot.qq_account)]
|
||||
|
||||
|
||||
|
||||
|
||||
def translate_pid_to_description(pid: str) -> str:
|
||||
image = Images.get_or_none(Images.image_id == pid)
|
||||
description = ""
|
||||
if image and image.description:
|
||||
description = image.description
|
||||
else:
|
||||
description = "[图片]"
|
||||
return description
|
||||
Loading…
Reference in New Issue