better:修改get_memoy tool以处理没有提取到记忆的情况
This commit is contained in:
@@ -472,8 +472,8 @@ class ActionPlanner:
|
||||
# 调用LLM
|
||||
llm_content, (reasoning_content, _, _) = await self.planner_llm.generate_response_async(prompt=prompt)
|
||||
|
||||
logger.info(f"{self.log_prefix}规划器原始提示词: {prompt}")
|
||||
logger.info(f"{self.log_prefix}规划器原始响应: {llm_content}")
|
||||
# logger.info(f"{self.log_prefix}规划器原始提示词: {prompt}")
|
||||
# logger.info(f"{self.log_prefix}规划器原始响应: {llm_content}")
|
||||
|
||||
if global_config.debug.show_prompt:
|
||||
logger.info(f"{self.log_prefix}规划器原始提示词: {prompt}")
|
||||
|
||||
@@ -485,6 +485,31 @@ class DefaultReplyer:
|
||||
) -> Tuple[str, str]:
|
||||
"""
|
||||
|
||||
Args:
|
||||
message_list_before_now: 历史消息列表
|
||||
target_user_id: 目标用户ID(当前对话对象)
|
||||
|
||||
Returns:
|
||||
Tuple[str, str]: (核心对话prompt, 背景对话prompt)
|
||||
"""
|
||||
# 构建背景对话 prompt
|
||||
all_dialogue_prompt = ""
|
||||
if message_list_before_now:
|
||||
latest_msgs = message_list_before_now[-int(global_config.chat.max_context_size) :]
|
||||
all_dialogue_prompt = build_readable_messages(
|
||||
latest_msgs,
|
||||
replace_bot_name=True,
|
||||
timestamp_mode="normal_no_YMD",
|
||||
truncate=True,
|
||||
)
|
||||
|
||||
return all_dialogue_prompt
|
||||
|
||||
def core_background_build_chat_history_prompts(
|
||||
self, message_list_before_now: List[DatabaseMessages], target_user_id: str, sender: str
|
||||
) -> Tuple[str, str]:
|
||||
"""
|
||||
|
||||
Args:
|
||||
message_list_before_now: 历史消息列表
|
||||
target_user_id: 目标用户ID(当前对话对象)
|
||||
@@ -792,9 +817,7 @@ class DefaultReplyer:
|
||||
reply_target_block = ""
|
||||
|
||||
# 构建分离的对话 prompt
|
||||
core_dialogue_prompt, background_dialogue_prompt = self.build_chat_history_prompts(
|
||||
message_list_before_now_long, user_id, sender
|
||||
)
|
||||
dialogue_prompt = self.build_chat_history_prompts(message_list_before_now_long, user_id, sender)
|
||||
|
||||
return await global_prompt_manager.format_prompt(
|
||||
"replyer_prompt",
|
||||
@@ -809,9 +832,8 @@ class DefaultReplyer:
|
||||
identity=personality_prompt,
|
||||
action_descriptions=actions_info,
|
||||
sender_name=sender,
|
||||
background_dialogue_prompt=background_dialogue_prompt,
|
||||
dialogue_prompt=dialogue_prompt,
|
||||
time_block=time_block,
|
||||
core_dialogue_prompt=core_dialogue_prompt,
|
||||
reply_target_block=reply_target_block,
|
||||
reply_style=global_config.personality.reply_style,
|
||||
keywords_reaction_prompt=keywords_reaction_prompt,
|
||||
|
||||
@@ -17,8 +17,7 @@ def init_replyer_prompt():
|
||||
|
||||
你正在qq群里聊天,下面是群里正在聊的内容:
|
||||
{time_block}
|
||||
{background_dialogue_prompt}
|
||||
{core_dialogue_prompt}
|
||||
{dialogue_prompt}
|
||||
|
||||
{reply_target_block}。
|
||||
{identity}
|
||||
|
||||
@@ -24,7 +24,7 @@ def init_rewrite_prompt():
|
||||
你可以完全重组回复,保留最基本的表达含义就好,但重组后保持语意通顺。
|
||||
{keywords_reaction_prompt}
|
||||
{moderation_prompt}
|
||||
不要输出多余内容(包括冒号和引号,表情包,emoji,at或 @等 ),只输出一条回复就好。
|
||||
不要输出多余内容(包括冒号和引号,表情包,emoji,at或 @等 ),只输出一条回复就好。不要思考的太长。
|
||||
改写后的回复:
|
||||
""",
|
||||
"default_expressor_prompt",
|
||||
|
||||
@@ -130,12 +130,15 @@ class GetMemoryTool(BaseTool):
|
||||
if memory_answer:
|
||||
content_parts.append(f"记忆仓库答案:{memory_answer}")
|
||||
else:
|
||||
content_parts.append("记忆仓库:没有找到相关记忆")
|
||||
content_parts.append(f"记忆仓库:对问题'{question}',没有什么印象")
|
||||
|
||||
if chat_answer:
|
||||
content_parts.append(f"聊天记录答案:{chat_answer}")
|
||||
content_parts.append(f"对问题'{question}',基于聊天记录的回答:{chat_answer}")
|
||||
elif has_time_params:
|
||||
content_parts.append("聊天记录:没有找到相关记录")
|
||||
if time_point:
|
||||
content_parts.append(f"在 {time_point} 的时间点,你没有参与聊天")
|
||||
elif time_range:
|
||||
content_parts.append(f"在 {time_range} 的时间范围内,你没有参与聊天")
|
||||
|
||||
return {"content": "\n".join(content_parts)}
|
||||
|
||||
@@ -191,35 +194,37 @@ class GetMemoryTool(BaseTool):
|
||||
request_type="chat_history_analysis"
|
||||
)
|
||||
|
||||
analysis_prompt = f"""请根据以下聊天记录内容,回答用户的问题。
|
||||
|
||||
analysis_prompt = f"""请根据以下聊天记录内容,回答用户的问题。请输出一段平文本,不要有特殊格式。
|
||||
聊天记录:
|
||||
{chat_content}
|
||||
|
||||
用户问题:{question}
|
||||
|
||||
请仔细分析聊天记录,提取与问题相关的信息,并给出准确的答案。如果聊天记录中没有相关信息,请说明"聊天记录中没有找到相关信息"。
|
||||
请仔细分析聊天记录,提取与问题相关的信息,并给出准确的答案。如果聊天记录中没有相关信息,无法回答问题,输出"无有效信息"即可,不要输出其他内容。
|
||||
|
||||
答案:"""
|
||||
|
||||
response, (reasoning, model_name, tool_calls) = await llm_request.generate_response_async(
|
||||
prompt=analysis_prompt,
|
||||
temperature=0.3,
|
||||
max_tokens=500
|
||||
max_tokens=256
|
||||
)
|
||||
|
||||
return f"基于聊天记录分析:{response}"
|
||||
if "无有效信息" in response:
|
||||
return ""
|
||||
|
||||
return response
|
||||
|
||||
except Exception as llm_error:
|
||||
logger.error(f"LLM分析聊天记录失败: {llm_error}")
|
||||
# 如果LLM分析失败,返回聊天内容的摘要
|
||||
if len(chat_content) > 300:
|
||||
chat_content = chat_content[:300] + "..."
|
||||
return f"聊天记录摘要:{chat_content}"
|
||||
return chat_content
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"从聊天记录获取答案失败: {e}")
|
||||
return f"聊天记录分析失败: {str(e)}"
|
||||
return ""
|
||||
|
||||
class GetMemoryAction(BaseAction):
|
||||
"""关系动作 - 获取记忆"""
|
||||
|
||||
Reference in New Issue
Block a user