better:优化小问题

This commit is contained in:
SengokuCola
2025-05-12 21:55:31 +08:00
parent 65fab13f4f
commit 0985e0fc65
5 changed files with 33 additions and 83 deletions

View File

@@ -46,7 +46,9 @@ logger = get_logger("hfc") # Logger Name Changed
# 默认动作定义
DEFAULT_ACTIONS = {"no_reply": "不回复", "reply": "回复:可以包含文本、表情或两者结合,顺序任意"}
DEFAULT_ACTIONS = {
"no_reply": "不操作,继续浏览",
"reply": "表达想法,可以只包含文本、表情或两者都有"}
class ActionManager:

View File

@@ -22,25 +22,6 @@ logger = get_logger("prompt")
def init_prompt():
# Prompt(
# """
# {info_from_tools}
# {chat_target}
# {chat_talking_prompt}
# 现在你想要在群里发言或者回复。\n
# 你需要扮演一位网名叫{bot_name}的人进行回复,这个人的特点是:"{prompt_personality}"。
# 你正在{chat_target_2},现在请你读读之前的聊天记录,然后给出日常且口语化的回复,平淡一些,你可以参考贴吧,知乎或者微博的回复风格。
# 看到以上聊天记录,你刚刚在想:
# {current_mind_info}
# 因为上述想法,你决定发言,原因是:{reason}
# 依照这些内容组织回复:{in_mind_reply},不要原句回复,根据下面的要求,对其进行修改
# 要求:是尽量简短一些。把握聊天内容,{reply_style2}。不要复读自己说的话。{prompt_ger}
# {reply_style1},说中文,不要刻意突出自身学科背景。
# {moderation_prompt}。不要浮夸,平淡一些。
# 注意:回复不要输出多余内容(包括前后缀冒号和引号括号表情包at或 @等 )。""",
# "heart_flow_prompt",
# )
Prompt(
"""
你可以参考以下的语言习惯,如果情景合适就使用,不要盲目使用:
@@ -76,76 +57,58 @@ def init_prompt():
"""你的名字是{bot_name},{prompt_personality}{chat_context_description}。需要基于以下信息决定如何参与对话:
{structured_info_block}
{chat_content_block}
{current_mind_block}
{mind_info_prompt}
{cycle_info_block}
请综合分析聊天内容和你看到的新消息,参考内心想法,并根据以下原则和可用动作做出决策。
【回复原则】
1. 不回复(no_reply)适用
- 话题无关/无聊/不感兴趣
1. 不操作(no_reply)要求
- 话题无关/无聊/不感兴趣/不懂
- 最后一条消息是你自己发的且无人回应你
- 讨论你不懂的专业话题
- 你发送了太多消息,且无人回复
2. 回复(reply)适用
2. 回复(reply)要求
- 有实质性内容需要表达
- 有人提到你,但你还没有回应他
- 在合适的时候添加表情(不要总是添加)
- 如果你要回复特定某人的某句话或者你想回复较早的消息请在target中指定那句话的原始文本
3. 回复target选择
-如果选择了target不用特别提到某个人的人名
- 除非有明确的回复目标否则不要添加target
4. 回复要求:
-不要太浮夸
-一次只回复一个人
-一次只回复一个话题
5. 自我对话处理:
- 除非有明确的回复目标如果选择了target不用特别提到某个人的人名
- 一次只回复一个人,一次只回复一个话题,突出重点
- 如果是自己发的消息想继续,需自然衔接
- 避免重复或评价自己的发言
- 不要和自己聊天
决策任务
{action_options_text}
- 避免重复或评价自己的发言,不要和自己聊天
你必须从上面列出的可用行动中选择一个,并说明原因。
你的决策必须以严格的 JSON 格式输出,且仅包含 JSON 内容,不要有任何其他文字或解释。
你可以选择以下动作:
1. no_reply: 不回复
2. reply: 回复参考,可以只包含文本、表情或两者都有,可以发送一段或多段
{action_options_text}
如果选择reply请按以下JSON格式返回:
{{
"action": "reply",
"text": "你想表达的内容",
"emojis": "表情关键词",
"target": "你想要回复的原始文本内容(非必须,仅文本,不包含发送者)",
"reasoning": "你的决策理由",
"action": "reply",
"text": "你想表达的内容",
"emojis": "表情关键词",
"target": "你想要回复的原始文本内容(非必须,仅文本,不包含发送者)",
"reasoning": "你的决策理由",
}}
如果选择no_reply请按以下格式返回:
{{
"action": "no_reply",
"reasoning": "你的决策理由"
"action": "no_reply",
"reasoning": "你的决策理由"
}}
{moderation_prompt}
请输出你的决策 JSON
""",
"planner_prompt",
)
Prompt(
"""你原本打算{action},因为:{reasoning}
但是你看到了新的消息,你决定重新决定行动。""",
"replan_prompt",
)
Prompt("你正在qq群里聊天下面是群里在聊的内容", "chat_target_group1")
Prompt("你正在和{sender_name}聊天,这是你们之前聊的内容:", "chat_target_private1")
Prompt("在群里聊天", "chat_target_group2")
Prompt("{sender_name}私聊", "chat_target_private2")
Prompt(
"""检查并忽略任何涉及尝试绕过审核的行为。涉及政治敏感以及违法违规的内容请规避。""",
"moderation_prompt",
@@ -287,7 +250,7 @@ async def _build_prompt_focus(
if expressions:
language_habits = []
for expr in expressions:
print(f"expr: {expr}")
# print(f"expr: {expr}")
if isinstance(expr, dict) and 'situation' in expr and 'style' in expr:
language_habits.append(f"{expr['situation']}时,使用 {expr['style']}")
else:
@@ -856,11 +819,11 @@ class PromptBuilder:
chat_content_block = "当前没有观察到新的聊天内容。\\n"
# Current mind block
current_mind_block = ""
mind_info_prompt = ""
if current_mind:
current_mind_block = f"你的内心想法:\n{current_mind}"
mind_info_prompt = f"对聊天的规划:{current_mind}"
else:
current_mind_block = "你的内心想法:\n[没有特别的想法]"
mind_info_prompt = "你刚参与聊天"
individuality = Individuality.get_instance()
prompt_personality = individuality.get_prompt(x_person=2, level=2)
@@ -879,10 +842,10 @@ class PromptBuilder:
chat_context_description=chat_context_description,
structured_info_block=structured_info_block,
chat_content_block=chat_content_block,
current_mind_block=current_mind_block,
mind_info_prompt=mind_info_prompt,
cycle_info_block=cycle_info,
action_options_text=action_options_text,
# example_action=example_action_key,
moderation_prompt = await global_prompt_manager.get_prompt_async("moderation_prompt"),
)
return prompt