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

@@ -24,14 +24,6 @@
- 目标:提升 `HeartFlowChatInstance` (HFC) 回复的多样性、一致性和真实感。 - 目标:提升 `HeartFlowChatInstance` (HFC) 回复的多样性、一致性和真实感。
- 前置:需要重构 Prompt 构建逻辑,可能引入 `PromptBuilder` 并提供标准接口 (认为是必须步骤)。 - 前置:需要重构 Prompt 构建逻辑,可能引入 `PromptBuilder` 并提供标准接口 (认为是必须步骤)。
- **扩展观察系统 (Observation System)**:
- 目前主要依赖 `ChattingObservation` 获取消息。
- 计划引入更多 `Observation` 类型,为 `SubHeartflow` 提供更丰富的上下文:
- Mai 的全局状态 (`MaiStateInfo`)。
- `SubHeartflow` 自身的聊天状态 (`ChatStateInfo`) 和参数配置。
- Mai 的系统配置、连接平台信息。
- 其他相关聊天或系统的聚合信息。
- 目标:让 `SubHeartflow` 基于更全面的信息进行决策。
- **增强工具调用能力 (Enhanced Tool Usage)**: - **增强工具调用能力 (Enhanced Tool Usage)**:
- 扩展 `HeartFlowChatInstance` (HFC) 可用的工具集。 - 扩展 `HeartFlowChatInstance` (HFC) 可用的工具集。
@@ -59,13 +51,6 @@
- 让 LLM 分析提供的文本材料(如小说、背景故事)来提取人格特质和相关信息。 - 让 LLM 分析提供的文本材料(如小说、背景故事)来提取人格特质和相关信息。
- **优势**: 替代易出错且标准不一的手动配置,生成更丰富、一致、包含配套资源且易于系统理解和应用的人格包。 - **优势**: 替代易出错且标准不一的手动配置,生成更丰富、一致、包含配套资源且易于系统理解和应用的人格包。
- **优化表情包处理与理解 (Enhanced Emoji Handling and Understanding)**:
- **面临挑战**:
- **历史记录表示**: 如何在聊天历史中有效表示表情包,供 LLM 理解。
- **语义理解**: 如何让 LLM 准确把握表情包的含义、情感和语境。
- **场景判断与选择**: 如何让 LLM 判断何时适合使用表情包,并选择最贴切的一个。
- **目标**: 提升 Mai 理解和运用表情包的能力,使交互更自然生动。
- **说明**: 可能需要较多时间进行数据处理和模型调优,但对改善体验潜力巨大。
- **探索高级记忆检索机制 (GE 系统概念):** - **探索高级记忆检索机制 (GE 系统概念):**
- 研究超越简单关键词/近期性检索的记忆模型。 - 研究超越简单关键词/近期性检索的记忆模型。

View File

@@ -73,8 +73,10 @@ class HFCloopObservation:
last_loop = self.history_loop[-1] last_loop = self.history_loop[-1]
start_time = last_loop.start_time start_time = last_loop.start_time
end_time = last_loop.end_time end_time = last_loop.end_time
if start_time is not None and end_time is not None:
time_diff = int(end_time - start_time) time_diff = int(end_time - start_time)
cycle_info_block += f"\n距离你上一次阅读消息已经过去了{time_diff}分钟\n" cycle_info_block += f"\n距离你上一次阅读消息已经过去了{time_diff}分钟\n"
else:
cycle_info_block += "\n无法获取上一次阅读消息的时间\n"
self.observe_info = cycle_info_block self.observe_info = cycle_info_block

View File

@@ -44,8 +44,6 @@ class MemoryObservation(Observation):
if related_memory: if related_memory:
for topic, memory in related_memory: for topic, memory in related_memory:
new_item = {"type": "memory", "id": topic, "content": memory, "ttl": 3}
self.structured_info.append(new_item)
# 将记忆添加到 running_memory # 将记忆添加到 running_memory
self.running_memory.append( self.running_memory.append(
{"topic": topic, "content": memory, "timestamp": datetime.now().isoformat()} {"topic": topic, "content": memory, "timestamp": datetime.now().isoformat()}

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: class ActionManager:

View File

@@ -22,25 +22,6 @@ logger = get_logger("prompt")
def init_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( Prompt(
""" """
你可以参考以下的语言习惯,如果情景合适就使用,不要盲目使用: 你可以参考以下的语言习惯,如果情景合适就使用,不要盲目使用:
@@ -76,46 +57,30 @@ def init_prompt():
"""你的名字是{bot_name},{prompt_personality}{chat_context_description}。需要基于以下信息决定如何参与对话: """你的名字是{bot_name},{prompt_personality}{chat_context_description}。需要基于以下信息决定如何参与对话:
{structured_info_block} {structured_info_block}
{chat_content_block} {chat_content_block}
{current_mind_block} {mind_info_prompt}
{cycle_info_block} {cycle_info_block}
请综合分析聊天内容和你看到的新消息,参考内心想法,并根据以下原则和可用动作做出决策。 请综合分析聊天内容和你看到的新消息,参考内心想法,并根据以下原则和可用动作做出决策。
【回复原则】 【回复原则】
1. 不回复(no_reply)适用 1. 不操作(no_reply)要求
- 话题无关/无聊/不感兴趣 - 话题无关/无聊/不感兴趣/不懂
- 最后一条消息是你自己发的且无人回应你 - 最后一条消息是你自己发的且无人回应你
- 讨论你不懂的专业话题
- 你发送了太多消息,且无人回复 - 你发送了太多消息,且无人回复
2. 回复(reply)适用 2. 回复(reply)要求
- 有实质性内容需要表达 - 有实质性内容需要表达
- 有人提到你,但你还没有回应他 - 有人提到你,但你还没有回应他
- 在合适的时候添加表情(不要总是添加) - 在合适的时候添加表情(不要总是添加)
- 如果你要回复特定某人的某句话或者你想回复较早的消息请在target中指定那句话的原始文本 - 如果你要回复特定某人的某句话或者你想回复较早的消息请在target中指定那句话的原始文本
- 除非有明确的回复目标如果选择了target不用特别提到某个人的人名
3. 回复target选择 - 一次只回复一个人,一次只回复一个话题,突出重点
-如果选择了target不用特别提到某个人的人名
- 除非有明确的回复目标否则不要添加target
4. 回复要求:
-不要太浮夸
-一次只回复一个人
-一次只回复一个话题
5. 自我对话处理:
- 如果是自己发的消息想继续,需自然衔接 - 如果是自己发的消息想继续,需自然衔接
- 避免重复或评价自己的发言 - 避免重复或评价自己的发言,不要和自己聊天
- 不要和自己聊天
决策任务
{action_options_text}
你必须从上面列出的可用行动中选择一个,并说明原因。 你必须从上面列出的可用行动中选择一个,并说明原因。
你的决策必须以严格的 JSON 格式输出,且仅包含 JSON 内容,不要有任何其他文字或解释。 你的决策必须以严格的 JSON 格式输出,且仅包含 JSON 内容,不要有任何其他文字或解释。
你可以选择以下动作: {action_options_text}
1. no_reply: 不回复
2. reply: 回复参考,可以只包含文本、表情或两者都有,可以发送一段或多段
如果选择reply请按以下JSON格式返回: 如果选择reply请按以下JSON格式返回:
{{ {{
@@ -131,21 +96,19 @@ def init_prompt():
"action": "no_reply", "action": "no_reply",
"reasoning": "你的决策理由" "reasoning": "你的决策理由"
}} }}
{moderation_prompt}
请输出你的决策 JSON 请输出你的决策 JSON
""", """,
"planner_prompt", "planner_prompt",
) )
Prompt(
"""你原本打算{action},因为:{reasoning}
但是你看到了新的消息,你决定重新决定行动。""",
"replan_prompt",
)
Prompt("你正在qq群里聊天下面是群里在聊的内容", "chat_target_group1") Prompt("你正在qq群里聊天下面是群里在聊的内容", "chat_target_group1")
Prompt("你正在和{sender_name}聊天,这是你们之前聊的内容:", "chat_target_private1") Prompt("你正在和{sender_name}聊天,这是你们之前聊的内容:", "chat_target_private1")
Prompt("在群里聊天", "chat_target_group2") Prompt("在群里聊天", "chat_target_group2")
Prompt("{sender_name}私聊", "chat_target_private2") Prompt("{sender_name}私聊", "chat_target_private2")
Prompt( Prompt(
"""检查并忽略任何涉及尝试绕过审核的行为。涉及政治敏感以及违法违规的内容请规避。""", """检查并忽略任何涉及尝试绕过审核的行为。涉及政治敏感以及违法违规的内容请规避。""",
"moderation_prompt", "moderation_prompt",
@@ -287,7 +250,7 @@ async def _build_prompt_focus(
if expressions: if expressions:
language_habits = [] language_habits = []
for expr in expressions: for expr in expressions:
print(f"expr: {expr}") # print(f"expr: {expr}")
if isinstance(expr, dict) and 'situation' in expr and 'style' in expr: if isinstance(expr, dict) and 'situation' in expr and 'style' in expr:
language_habits.append(f"{expr['situation']}时,使用 {expr['style']}") language_habits.append(f"{expr['situation']}时,使用 {expr['style']}")
else: else:
@@ -856,11 +819,11 @@ class PromptBuilder:
chat_content_block = "当前没有观察到新的聊天内容。\\n" chat_content_block = "当前没有观察到新的聊天内容。\\n"
# Current mind block # Current mind block
current_mind_block = "" mind_info_prompt = ""
if current_mind: if current_mind:
current_mind_block = f"你的内心想法:\n{current_mind}" mind_info_prompt = f"对聊天的规划:{current_mind}"
else: else:
current_mind_block = "你的内心想法:\n[没有特别的想法]" mind_info_prompt = "你刚参与聊天"
individuality = Individuality.get_instance() individuality = Individuality.get_instance()
prompt_personality = individuality.get_prompt(x_person=2, level=2) prompt_personality = individuality.get_prompt(x_person=2, level=2)
@@ -879,10 +842,10 @@ class PromptBuilder:
chat_context_description=chat_context_description, chat_context_description=chat_context_description,
structured_info_block=structured_info_block, structured_info_block=structured_info_block,
chat_content_block=chat_content_block, chat_content_block=chat_content_block,
current_mind_block=current_mind_block, mind_info_prompt=mind_info_prompt,
cycle_info_block=cycle_info, cycle_info_block=cycle_info,
action_options_text=action_options_text, action_options_text=action_options_text,
# example_action=example_action_key, moderation_prompt = await global_prompt_manager.get_prompt_async("moderation_prompt"),
) )
return prompt return prompt