|
|
@@ -35,7 +35,7 @@
|
|
|
"- `get_attraction(city: str, weather: str)`: 根据城市和天气搜索推荐的旅游景点。\n",
|
|
|
"\n",
|
|
|
"# 行动格式:\n",
|
|
|
- "你的回答必须严格遵循以下格式。首先是你的思考过程,然后是你要执行的具体行动。\n",
|
|
|
+ "你的回答必须严格遵循以下格式。首先是你的思考过程,然后是你要执行的具体行动,每次回复只输出一对Thought-Action:\n",
|
|
|
"Thought: [这里是你的思考过程和下一步计划]\n",
|
|
|
"Action: [这里是你要调用的工具,格式为 function_name(arg_name=\"arg_value\")]\n",
|
|
|
"\n",
|
|
|
@@ -269,7 +269,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 5,
|
|
|
+ "execution_count": null,
|
|
|
"id": "cc543309-fe16-44a9-9735-bce828b9c7ad",
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
@@ -300,6 +300,13 @@
|
|
|
" # 构建完整prompt并调用LLM\n",
|
|
|
" full_prompt = \"\\n\".join(assistant.prompt_history)\n",
|
|
|
" llm_output = assistant.llm.generate(full_prompt, AGENT_SYSTEM_PROMPT)\n",
|
|
|
+ " # 模型可能会输出多余的Thought-Action,需要截断\n",
|
|
|
+ " match = re.search(r'(Thought:.*?Action:.*?)(?=\\n\\s*(?:Thought:|Action:|Observation:)|\\Z)', llm_output, re.DOTALL)\n",
|
|
|
+ " if match:\n",
|
|
|
+ " truncated = match.group(1).strip()\n",
|
|
|
+ " if truncated != llm_output.strip():\n",
|
|
|
+ " llm_output = truncated\n",
|
|
|
+ " print(\"⚠️ 已截断多余的 Thought-Action 对\")\n",
|
|
|
" \n",
|
|
|
" assistant.add_assistant_message(llm_output)\n",
|
|
|
" \n",
|