From eaa1f445cd7ef097981412b5087281cadd3438fc Mon Sep 17 00:00:00 2001 From: zihanjian Date: Fri, 18 Jul 2025 14:17:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ai=5Frouter):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=8F=90=E7=A4=BA=E6=A0=BC=E5=BC=8F=E5=B9=B6?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/ai_router.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/commands/ai_router.py b/commands/ai_router.py index c6742b1..b8c37bf 100644 --- a/commands/ai_router.py +++ b/commands/ai_router.py @@ -58,7 +58,7 @@ class AIRouter: 可用的功能列表: """ for name, func in self.functions.items(): - prompt += f"\n{name}: {func.description}" + prompt += f"\n- {name}: {func.description}" if func.params_description: prompt += f"\n 参数: {func.params_description}" if func.examples: @@ -66,26 +66,30 @@ class AIRouter: prompt += "\n" prompt += """ -请分析用户输入,返回以下JSON格式之一: +分析用户输入,严格按照以下格式返回JSON: -1. 如果用户需要执行某个功能: +如果用户需要使用上述功能之一,返回: { "action_type": "function", - "function_name": "功能名称", - "params": "提取并整理的参数" + "function_name": "上述功能列表中的功能名", + "params": "从用户输入中提取的参数" } -2. 如果用户只是想聊天对话: +如果用户只是聊天或者不匹配任何功能,返回: { "action_type": "chat" } -重要提示: -- 只返回JSON,不要有其他文字 -- action_type 必须是 "function" 或 "chat" 之一,不能是其他值 -- function_name必须是上述列表中的功能名之一 -- params是你从用户输入中提取和整理的参数字符串 -- 如果无法确定用户意图,默认返回chat +示例: +- 用户输入"北京天气怎么样" -> {"action_type": "function", "function_name": "weather_query", "params": "北京"} +- 用户输入"看看新闻" -> {"action_type": "function", "function_name": "news_query", "params": ""} +- 用户输入"你好" -> {"action_type": "chat"} +- 用户输入"查一下Python教程" -> {"action_type": "function", "function_name": "perplexity_search", "params": "Python教程"} + +重要: +1. action_type 只能是 "function" 或 "chat" +2. 只返回JSON,无需其他解释 +3. function_name 必须完全匹配上述功能列表中的名称 """ return prompt