简单模式增加查询

This commit is contained in:
2025-09-14 21:09:54 +08:00
parent 7bf8210b80
commit 9703f7cc10

View File

@@ -636,27 +636,25 @@ class PyTreeGenerator:
except Exception as e: except Exception as e:
logging.warning(f"分类失败,默认按复杂指令处理: {e}") logging.warning(f"分类失败,默认按复杂指令处理: {e}")
# 第二步:根据模式准备提示词与上下文 # 第二步:根据模式准备提示词与上下文(简单与复杂都执行检索增强)
# 基于模式选择提示词;复杂模式追加一条强制规则,避免模型误输出简单结构 # 基于模式选择提示词;复杂模式追加一条强制规则,避免模型误输出简单结构
use_prompt = self.simple_prompt if mode == "simple" else ( use_prompt = self.simple_prompt if mode == "simple" else (
(self.complex_prompt or "") + (self.complex_prompt or "") +
"\n\n【强制规则】仅生成包含root的复杂行为树JSON不得输出简单模式不得包含mode字段或仅有action节点" "\n\n【强制规则】仅生成包含root的复杂行为树JSON不得输出简单模式不得包含mode字段或仅有action节点"
) )
final_user_prompt = user_prompt final_user_prompt = user_prompt
retrieved_context = None retrieved_context = self._retrieve_context(user_prompt)
if mode == "complex": if retrieved_context:
retrieved_context = self._retrieve_context(user_prompt) augmentation = (
if retrieved_context: "\n\n---\n"
augmentation = ( "参考知识:\n"
"\n\n---\n" "以下是从知识库中检索到的、与当前任务最相关的信息,请优先参考这些信息来生成结果:\n"
"参考知识:\n" f"{retrieved_context}"
"以下是从知识库中检索到的、与当前任务最相关的信息,请优先参考这些信息来生成行为树:\n" "\n---"
f"{retrieved_context}" )
"\n---" final_user_prompt += augmentation
) else:
final_user_prompt += augmentation logging.warning("未检索到上下文或检索失败,将使用原始用户提示词。")
else:
logging.warning("未检索到上下文或检索失败,将使用原始用户提示词。")
for attempt in range(3): for attempt in range(3):
logging.info(f"--- 第 {attempt + 1}/3 次尝试生成Pytree ---") logging.info(f"--- 第 {attempt + 1}/3 次尝试生成Pytree ---")
try: try: