better:优化prompt,修改buffer行为(更严格判定降低延迟,不丢弃图片前文本)
This commit is contained in:
@@ -405,7 +405,7 @@ class HeartFChatting:
|
||||
return False, ""
|
||||
|
||||
# execute:执行
|
||||
with Timer("执行", cycle_timers):
|
||||
with Timer("执行动作", cycle_timers):
|
||||
return await self._handle_action(action, reasoning, planner_result.get("emoji_query", ""), cycle_timers, planner_start_db_time)
|
||||
|
||||
except PlannerError as e:
|
||||
@@ -490,7 +490,7 @@ class HeartFChatting:
|
||||
|
||||
try:
|
||||
# 生成回复
|
||||
with Timer("Replier", cycle_timers):
|
||||
with Timer("生成回复", cycle_timers):
|
||||
reply = await self._replier_work(
|
||||
anchor_message=anchor_message,
|
||||
thinking_id=thinking_id,
|
||||
@@ -501,13 +501,13 @@ class HeartFChatting:
|
||||
raise ReplierError("回复生成失败")
|
||||
|
||||
# 发送消息
|
||||
with Timer("Sender", cycle_timers):
|
||||
await self._sender(
|
||||
thinking_id=thinking_id,
|
||||
anchor_message=anchor_message,
|
||||
response_set=reply,
|
||||
send_emoji=emoji_query,
|
||||
)
|
||||
|
||||
await self._sender(
|
||||
thinking_id=thinking_id,
|
||||
anchor_message=anchor_message,
|
||||
response_set=reply,
|
||||
send_emoji=emoji_query,
|
||||
)
|
||||
|
||||
return True, thinking_id
|
||||
|
||||
@@ -675,7 +675,7 @@ class HeartFChatting:
|
||||
# 获取观察信息
|
||||
observation = self.observations[0]
|
||||
if is_re_planned:
|
||||
observation.observe()
|
||||
await observation.observe()
|
||||
observed_messages = observation.talking_message
|
||||
observed_messages_str = observation.talking_message_str
|
||||
|
||||
@@ -687,40 +687,40 @@ class HeartFChatting:
|
||||
|
||||
try:
|
||||
# 构建提示词
|
||||
with Timer("构建提示词", cycle_timers):
|
||||
if is_re_planned:
|
||||
replan_prompt = await self._build_replan_prompt(
|
||||
self._current_cycle.action, self._current_cycle.reasoning
|
||||
)
|
||||
prompt = replan_prompt
|
||||
else:
|
||||
replan_prompt = ""
|
||||
prompt = await self._build_planner_prompt(
|
||||
observed_messages_str, current_mind, self.sub_mind.structured_info, replan_prompt
|
||||
|
||||
if is_re_planned:
|
||||
replan_prompt = await self._build_replan_prompt(
|
||||
self._current_cycle.action_type, self._current_cycle.reasoning
|
||||
)
|
||||
payload = {
|
||||
"model": global_config.llm_plan["name"],
|
||||
"messages": [{"role": "user", "content": prompt}],
|
||||
"tools": self.action_manager.get_planner_tool_definition(),
|
||||
"tool_choice": {"type": "function", "function": {"name": "decide_reply_action"}},
|
||||
}
|
||||
prompt = replan_prompt
|
||||
else:
|
||||
replan_prompt = ""
|
||||
prompt = await self._build_planner_prompt(
|
||||
observed_messages_str, current_mind, self.sub_mind.structured_info, replan_prompt
|
||||
)
|
||||
payload = {
|
||||
"model": global_config.llm_plan["name"],
|
||||
"messages": [{"role": "user", "content": prompt}],
|
||||
"tools": self.action_manager.get_planner_tool_definition(),
|
||||
"tool_choice": {"type": "function", "function": {"name": "decide_reply_action"}},
|
||||
}
|
||||
|
||||
# 执行LLM请求
|
||||
with Timer("LLM回复", cycle_timers):
|
||||
try:
|
||||
response = await self.planner_llm._execute_request(
|
||||
endpoint="/chat/completions", payload=payload, prompt=prompt
|
||||
)
|
||||
except Exception as req_e:
|
||||
logger.error(f"{self.log_prefix}[Planner] LLM请求执行失败: {req_e}")
|
||||
return {
|
||||
"action": "error",
|
||||
"reasoning": f"LLM请求执行失败: {req_e}",
|
||||
"emoji_query": "",
|
||||
"current_mind": current_mind,
|
||||
"observed_messages": observed_messages,
|
||||
"llm_error": True,
|
||||
}
|
||||
|
||||
try:
|
||||
response = await self.planner_llm._execute_request(
|
||||
endpoint="/chat/completions", payload=payload, prompt=prompt
|
||||
)
|
||||
except Exception as req_e:
|
||||
logger.error(f"{self.log_prefix}[Planner] LLM请求执行失败: {req_e}")
|
||||
return {
|
||||
"action": "error",
|
||||
"reasoning": f"LLM请求执行失败: {req_e}",
|
||||
"emoji_query": "",
|
||||
"current_mind": current_mind,
|
||||
"observed_messages": observed_messages,
|
||||
"llm_error": True,
|
||||
}
|
||||
|
||||
# 处理LLM响应
|
||||
with Timer("使用工具", cycle_timers):
|
||||
@@ -883,7 +883,7 @@ class HeartFChatting:
|
||||
# 准备聊天内容块
|
||||
chat_content_block = ""
|
||||
if observed_messages_str:
|
||||
chat_content_block = "观察到的最新聊天内容如下 (最近的消息在最后):\n---\n"
|
||||
chat_content_block = "观察到的最新聊天内容如下:\n---\n"
|
||||
chat_content_block += observed_messages_str
|
||||
chat_content_block += "\n---"
|
||||
else:
|
||||
@@ -892,9 +892,9 @@ class HeartFChatting:
|
||||
# 准备当前思维块
|
||||
current_mind_block = ""
|
||||
if current_mind:
|
||||
current_mind_block = f"\n---\n{current_mind}\n---\n\n"
|
||||
current_mind_block = f"{current_mind}"
|
||||
else:
|
||||
current_mind_block = " [没有特别的想法] \n\n"
|
||||
current_mind_block = "[没有特别的想法]"
|
||||
|
||||
# 获取提示词模板并填充数据
|
||||
prompt = (await global_prompt_manager.get_prompt_async("planner_prompt")).format(
|
||||
|
||||
@@ -44,28 +44,49 @@ def init_prompt():
|
||||
以上的消息是你获取到的消息,或许可以帮助你更好地回复。
|
||||
""", "info_from_tools")
|
||||
|
||||
# Planner提示词
|
||||
# Planner提示词 - 优化版
|
||||
Prompt(
|
||||
"""你的名字是 {bot_name}。是一个女大二学生,正在QQ聊天,正在决定是否以及如何回应当前的聊天。
|
||||
"""你的名字是{bot_name},一名大二女生,正在QQ群聊中。需要基于以下信息决定如何参与对话:
|
||||
{structured_info_block}
|
||||
{chat_content_block}
|
||||
看了以上内容,你产生的内心想法是:
|
||||
你的内心想法:
|
||||
{current_mind_block}
|
||||
{replan}
|
||||
请结合你的内心想法和观察到的聊天内容,分析情况并使用 'decide_reply_action' 工具来决定你的最终行动。
|
||||
注意你必须参考以下决策依据来选择工具:
|
||||
1. 如果聊天内容无聊、与你无关、或者你的内心想法认为不适合回复(例如在讨论你不懂或不感兴趣的话题),选择 'no_reply'。
|
||||
2. 如果聊天内容值得回应,且适合用文字表达(参考你的内心想法),选择 'text_reply'。如果你有情绪想表达,想在文字后追加一个表达情绪的表情,请同时提供 'emoji_query' (每个标签用一个词组表示,格式例如:幽默的讽刺,单纯的开心,愤怒的抗议)。
|
||||
3. 如果聊天内容或你的内心想法适合用一个表情来回应,选择 'emoji_reply' 并提供表情主题 'emoji_query'。
|
||||
4. 如果最后一条消息是你自己发的,观察到的内容只有你自己的发言,并且之后没有人回复你,通常选择 'no_reply',除非有特殊原因需要追问。
|
||||
5. 如果聊天记录中最新的消息是你自己发送的,并且你还想继续回复,你应该紧紧衔接你发送的消息,进行话题的深入,补充,或追问等等;。
|
||||
6. 表情包是用来表达情绪的,不要直接回复或评价别人的表情包,而是根据对话内容和情绪选择是否用表情回应。
|
||||
7. 不要回复你自己的话,不要把自己的话当做别人说的。
|
||||
必须调用 'decide_reply_action' 工具并提供 'action' 和 'reasoning'。如果选择了 'emoji_reply' 或者选择了 'text_reply' 并想追加表情,则必须提供 'emoji_query'。""",
|
||||
|
||||
请综合分析聊天内容和你看到的新消息,参考内心想法,使用'decide_reply_action'工具做出决策。决策时请注意:
|
||||
|
||||
【回复原则】
|
||||
1. 不回复(no_reply)适用:
|
||||
- 话题无关/无聊/不感兴趣
|
||||
- 最后一条消息是你自己发的且无人回应你
|
||||
- 讨论你不懂的专业话题
|
||||
- 讨论你不想参与的话题
|
||||
- 你发送了太多消息
|
||||
|
||||
2. 文字回复(text_reply)适用:
|
||||
- 有实质性内容需要表达
|
||||
- 可以追加emoji_query表达情绪(格式:情绪描述,如"俏皮的调侃")
|
||||
- 不要追加太多表情
|
||||
|
||||
3. 纯表情回复(emoji_reply)适用:
|
||||
- 适合用表情回应的场景
|
||||
- 需提供明确的emoji_query
|
||||
|
||||
4. 自我对话处理:
|
||||
- 如果是自己发的消息想继续,需自然衔接
|
||||
- 避免重复或评价自己的发言
|
||||
- 不要和自己聊天
|
||||
|
||||
【必须遵守】
|
||||
- 必须调用工具并包含action和reasoning
|
||||
- 你可以选择文字回复(text_reply),纯表情回复(emoji_reply),不回复(no_reply)
|
||||
- 选择text_reply或emoji_reply时必须提供emoji_query
|
||||
- 保持回复自然,符合日常聊天习惯""",
|
||||
"planner_prompt",
|
||||
)
|
||||
|
||||
Prompt("你原本打算{action},因为:{reasoning},但是你看到了新的消息,你决定重新决定行动。", "replan_prompt")
|
||||
Prompt('''你原本打算{action},因为:{reasoning}
|
||||
但是你看到了新的消息,你决定重新决定行动。''', "replan_prompt")
|
||||
|
||||
Prompt("你正在qq群里聊天,下面是群里在聊的内容:", "chat_target_group1")
|
||||
Prompt("和群里聊天", "chat_target_group2")
|
||||
|
||||
Reference in New Issue
Block a user