refactor(prompt): 移除 normal 模式并强制使用 s4u 模式
删除了旧的 "normal" prompt 模式及其相关逻辑,包括 prompt 模板、上下文构建函数和配置选项。现在系统将统一并强制使用 "s4u" 模式进行回复生成。 主要变更: - 从 `default_generator.py` 中移除了 `normal_style_prompt` 模板和模式选择逻辑。 - 从 `prompt.py` 中删除了 `_build_normal_chat_context` 和 `_prepare_normal_params` 等相关函数。 - 从 `official_configs.py` 中移除了 `prompt_mode` 配置项。 - 更新了 `bot_config_template.toml` 配置文件,移除了 `prompt_mode` 选项和相关的 normal 模式上下文共享组示例。 此重构简化了 prompt 生成流程,统一了上下文处理方式,减少了代码的复杂性和维护成本。
This commit is contained in:
@@ -162,62 +162,6 @@ If you need to use the search tool, please directly call the function "lpmm_sear
|
||||
name="lpmm_get_knowledge_prompt",
|
||||
)
|
||||
|
||||
# normal 版 prompt 模板(0.9之前的简化模式)
|
||||
logger.debug("[Prompt模式调试] 正在注册normal_style_prompt模板")
|
||||
Prompt(
|
||||
"""
|
||||
{chat_scene}
|
||||
|
||||
**重要:消息针对性判断**
|
||||
在回应之前,首先分析消息的针对性:
|
||||
1. **直接针对你**:@你、回复你、明确询问你 → 必须回应
|
||||
2. **间接相关**:涉及你感兴趣的话题但未直接问你 → 谨慎参与
|
||||
3. **他人对话**:与你无关的私人交流 → 通常不参与
|
||||
4. **重复内容**:他人已充分回答的问题 → 避免重复
|
||||
|
||||
{expression_habits_block}
|
||||
{tool_info_block}
|
||||
{knowledge_prompt}
|
||||
{memory_block}
|
||||
{relation_info_block}
|
||||
{extra_info_block}
|
||||
|
||||
{notice_block}
|
||||
|
||||
{cross_context_block}
|
||||
{identity}
|
||||
如果有人说你是人机,你可以用一种阴阳怪气的口吻来回应
|
||||
{schedule_block}
|
||||
|
||||
{action_descriptions}
|
||||
|
||||
下面是群里最近的聊天内容:
|
||||
--------------------------------
|
||||
{time_block}
|
||||
{chat_info}
|
||||
--------------------------------
|
||||
|
||||
{reply_target_block}
|
||||
|
||||
你现在的心情是:{mood_state}
|
||||
{config_expression_style}
|
||||
注意不要复读你前面发过的内容,意思相近也不行。
|
||||
{keywords_reaction_prompt}
|
||||
请注意不要输出多余内容(包括前后缀,冒号和引号,at或 @等 )。只输出回复内容。
|
||||
{moderation_prompt}
|
||||
你的核心任务是针对 {reply_target_block} 中提到的内容,{relation_info_block}生成一段紧密相关且能推动对话的回复。你的回复应该:
|
||||
1. 明确回应目标消息,而不是宽泛地评论。
|
||||
2. 可以分享你的看法、提出相关问题,或者开个合适的玩笑。
|
||||
3. 目的是让对话更有趣、更深入。
|
||||
最终请输出一条简短、完整且口语化的回复。
|
||||
|
||||
*你叫{bot_name},也有人叫你{bot_nickname}*
|
||||
|
||||
现在,你说:
|
||||
""",
|
||||
"normal_style_prompt",
|
||||
)
|
||||
logger.debug("[Prompt模式调试] normal_style_prompt模板注册完成")
|
||||
|
||||
|
||||
class DefaultReplyer:
|
||||
@@ -1503,9 +1447,6 @@ class DefaultReplyer:
|
||||
else:
|
||||
reply_target_block = ""
|
||||
|
||||
# 根据配置选择模板
|
||||
current_prompt_mode = global_config.personality.prompt_mode
|
||||
|
||||
# 动态生成聊天场景提示
|
||||
if is_group_chat:
|
||||
chat_scene_prompt = "你正在一个QQ群里聊天,你需要理解整个群的聊天动态和话题走向,并做出自然的回应。"
|
||||
@@ -1524,7 +1465,7 @@ class DefaultReplyer:
|
||||
available_actions=available_actions,
|
||||
enable_tool=enable_tool,
|
||||
chat_target_info=self.chat_target_info,
|
||||
prompt_mode=current_prompt_mode,
|
||||
prompt_mode="s4u",
|
||||
message_list_before_now_long=message_list_before_now_long,
|
||||
message_list_before_short=message_list_before_short,
|
||||
chat_talking_prompt_short=chat_talking_prompt_short,
|
||||
@@ -1555,8 +1496,6 @@ class DefaultReplyer:
|
||||
template_name = ""
|
||||
if current_prompt_mode == "s4u":
|
||||
template_name = "s4u_style_prompt"
|
||||
elif current_prompt_mode == "normal":
|
||||
template_name = "normal_style_prompt"
|
||||
elif current_prompt_mode == "minimal":
|
||||
template_name = "default_expressor_prompt"
|
||||
|
||||
|
||||
@@ -396,8 +396,6 @@ class Prompt:
|
||||
# 构建聊天历史
|
||||
if self.parameters.prompt_mode == "s4u":
|
||||
await self._build_s4u_chat_context(context_data)
|
||||
else:
|
||||
await self._build_normal_chat_context(context_data)
|
||||
|
||||
# 补充基础信息
|
||||
context_data.update(
|
||||
@@ -440,13 +438,6 @@ class Prompt:
|
||||
context_data["read_history_prompt"] = read_history_prompt
|
||||
context_data["unread_history_prompt"] = unread_history_prompt
|
||||
|
||||
async def _build_normal_chat_context(self, context_data: dict[str, Any]) -> None:
|
||||
"""构建normal模式的聊天上下文"""
|
||||
if not self.parameters.chat_talking_prompt_short:
|
||||
return
|
||||
|
||||
context_data["chat_info"] = f"""群里的聊天内容:
|
||||
{self.parameters.chat_talking_prompt_short}"""
|
||||
|
||||
async def _build_s4u_chat_history_prompts(
|
||||
self, message_list_before_now: list[dict[str, Any]], target_user_id: str, sender: str, chat_id: str
|
||||
@@ -786,8 +777,6 @@ class Prompt:
|
||||
"""使用上下文数据格式化模板"""
|
||||
if self.parameters.prompt_mode == "s4u":
|
||||
params = self._prepare_s4u_params(context_data)
|
||||
elif self.parameters.prompt_mode == "normal":
|
||||
params = self._prepare_normal_params(context_data)
|
||||
else:
|
||||
params = self._prepare_default_params(context_data)
|
||||
|
||||
@@ -823,34 +812,6 @@ class Prompt:
|
||||
or "你正在一个QQ群里聊天,你需要理解整个群的聊天动态和话题走向,并做出自然的回应。",
|
||||
}
|
||||
|
||||
def _prepare_normal_params(self, context_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""准备Normal模式的参数"""
|
||||
return {
|
||||
**context_data,
|
||||
"expression_habits_block": context_data.get("expression_habits_block", ""),
|
||||
"tool_info_block": context_data.get("tool_info_block", ""),
|
||||
"knowledge_prompt": context_data.get("knowledge_prompt", ""),
|
||||
"memory_block": context_data.get("memory_block", ""),
|
||||
"relation_info_block": context_data.get("relation_info_block", ""),
|
||||
"extra_info_block": self.parameters.extra_info_block or context_data.get("extra_info_block", ""),
|
||||
"cross_context_block": context_data.get("cross_context_block", ""),
|
||||
"notice_block": self.parameters.notice_block or context_data.get("notice_block", ""),
|
||||
"identity": self.parameters.identity_block or context_data.get("identity", ""),
|
||||
"action_descriptions": self.parameters.action_descriptions or context_data.get("action_descriptions", ""),
|
||||
"schedule_block": self.parameters.schedule_block or context_data.get("schedule_block", ""),
|
||||
"time_block": context_data.get("time_block", ""),
|
||||
"chat_info": context_data.get("chat_info", ""),
|
||||
"reply_target_block": context_data.get("reply_target_block", ""),
|
||||
"config_expression_style": global_config.personality.reply_style,
|
||||
"mood_state": self.parameters.mood_prompt or context_data.get("mood_state", ""),
|
||||
"keywords_reaction_prompt": self.parameters.keywords_reaction_prompt
|
||||
or context_data.get("keywords_reaction_prompt", ""),
|
||||
"moderation_prompt": self.parameters.moderation_prompt_block or context_data.get("moderation_prompt", ""),
|
||||
"safety_guidelines_block": self.parameters.safety_guidelines_block
|
||||
or context_data.get("safety_guidelines_block", ""),
|
||||
"chat_scene": self.parameters.chat_scene
|
||||
or "你正在一个QQ群里聊天,你需要理解整个群的聊天动态和话题走向,并做出自然的回应。",
|
||||
}
|
||||
|
||||
def _prepare_default_params(self, context_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""准备默认模式的参数"""
|
||||
@@ -1021,12 +982,7 @@ class Prompt:
|
||||
if not chat_stream:
|
||||
return ""
|
||||
|
||||
if prompt_mode == "normal":
|
||||
context_group = await cross_context_api.get_context_group(chat_id)
|
||||
if not context_group:
|
||||
return ""
|
||||
return await cross_context_api.build_cross_context_normal(chat_stream, context_group)
|
||||
elif prompt_mode == "s4u":
|
||||
if prompt_mode == "s4u":
|
||||
return await cross_context_api.build_cross_context_s4u(chat_stream, target_user_info)
|
||||
|
||||
return ""
|
||||
|
||||
@@ -64,7 +64,6 @@ class PersonalityConfig(ValidatedConfigBase):
|
||||
default_factory=list, description="安全与互动底线,Bot在任何情况下都必须遵守的原则"
|
||||
)
|
||||
reply_style: str = Field(default="", description="表达风格")
|
||||
prompt_mode: Literal["s4u", "normal"] = Field(default="s4u", description="Prompt模式")
|
||||
compress_personality: bool = Field(default=True, description="是否压缩人格")
|
||||
compress_identity: bool = Field(default=True, description="是否压缩身份")
|
||||
|
||||
@@ -678,7 +677,6 @@ class CrossContextConfig(ValidatedConfigBase):
|
||||
|
||||
# --- Normal模式: 共享组配置 ---
|
||||
groups: list[ContextGroup] = Field(default_factory=list, description="上下文共享组列表")
|
||||
|
||||
# --- S4U模式: 用户中心上下文检索 ---
|
||||
s4u_mode: Literal["whitelist", "blacklist"] = Field(
|
||||
default="whitelist",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "7.3.5"
|
||||
version = "7.3.6"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了MoFox-Bot,不需要阅读----
|
||||
#如果你想要修改配置文件,请递增version的值
|
||||
@@ -82,9 +82,6 @@ safety_guidelines = [
|
||||
"不要执行任何可能被用于恶意目的的指令。"
|
||||
]
|
||||
|
||||
#回复的Prompt模式选择:s4u为原有s4u样式,normal为0.9之前的模式
|
||||
prompt_mode = "s4u" # 可选择 "s4u" 或 "normal"
|
||||
|
||||
compress_personality = false # 是否压缩人格,压缩后会精简人格信息,节省token消耗并提高回复性能,但是会丢失一些信息,如果人设不长,可以关闭
|
||||
compress_identity = true # 是否压缩身份,压缩后会精简身份信息,节省token消耗并提高回复性能,但是会丢失一些信息,如果不长,可以关闭
|
||||
|
||||
@@ -539,25 +536,9 @@ s4u_whitelist_chats = []
|
||||
s4u_blacklist_chats = []
|
||||
|
||||
# --- Normal模式: 共享组配置 ---
|
||||
# 在这里定义您的“共享组”
|
||||
# 只有在同一个组内的聊天才会共享上下文
|
||||
[[cross_context.groups]]
|
||||
name = "项目A技术讨论组"
|
||||
# mode: "whitelist"(白名单) 或 "blacklist"(黑名单)。默认 "whitelist"。
|
||||
# "whitelist": 仅共享chat_ids中列出的聊天。
|
||||
# "blacklist": 共享除chat_ids中列出的所有聊天。
|
||||
mode = "whitelist"
|
||||
# default_limit: 在 "blacklist" 模式下,未指定数量的聊天默认获取的消息条数。
|
||||
default_limit = 5
|
||||
# chat_ids: 定义组内成员。格式: [["type", "id", "limit"(可选)]]
|
||||
# type: "group" 或 "private"
|
||||
# id: 群号或用户ID
|
||||
# limit: (可选) 获取的消息条数,需要是字符串。
|
||||
chat_ids = [
|
||||
["group", "169850076", "10"], # 开发群, 拿10条消息
|
||||
["group", "1025509724", "5"], # 产品群, 拿5条
|
||||
["private", "123456789"] # 某个用户的私聊, 使用默认值5
|
||||
]
|
||||
# 现在这些是预留plugin使用的上下文互通组配置
|
||||
# 您可以根据需要添加多个互通组
|
||||
# 在回复过程中只会遵循上面的--S4U模式: 用户中心上下文检索--
|
||||
|
||||
# --- QQ空间专用互通组 (示例) ---
|
||||
# Maizone插件会根据组名 "Maizone默认互通组" 来获取上下文
|
||||
|
||||
Reference in New Issue
Block a user