From 22c666b4bfc28fe4607b4972da2c2fff981c25d3 Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Fri, 14 Feb 2025 07:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=8D=E7=94=A8=E7=9A=84to?= =?UTF-8?q?ol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/intention/大模型意图识别提示词.txt | 10 +- docs/intention/大模型意图识别提示词V2.txt | 144 ++++++++++++++++++ docs/intention/意图识别.txt | 24 +++ docs/intention/数据查询参数抽取.txt | 72 +++++++++ .../agent/tools_factory/amap_poi_search.py | 2 +- .../agent/tools_factory/amap_weather.py | 2 +- .../server/agent/tools_factory/arxiv.py | 2 +- .../server/agent/tools_factory/calculate.py | 2 +- .../agent/tools_factory/search_internet.py | 2 +- .../search_local_knowledgebase.py | 4 +- .../agent/tools_factory/search_youtube.py | 2 +- .../server/agent/tools_factory/shell.py | 2 +- .../server/agent/tools_factory/text2image.py | 2 +- .../server/agent/tools_factory/text2promql.py | 2 +- .../server/agent/tools_factory/text2sql.py | 2 +- .../server/agent/tools_factory/url_reader.py | 2 +- .../agent/tools_factory/weather_check.py | 3 +- .../agent/tools_factory/wikipedia_search.py | 2 +- .../server/agent/tools_factory/wolfram.py | 2 +- 19 files changed, 262 insertions(+), 21 deletions(-) create mode 100644 docs/intention/大模型意图识别提示词V2.txt create mode 100644 docs/intention/意图识别.txt create mode 100644 docs/intention/数据查询参数抽取.txt diff --git a/docs/intention/大模型意图识别提示词.txt b/docs/intention/大模型意图识别提示词.txt index be6bdd7..6b99636 100644 --- a/docs/intention/大模型意图识别提示词.txt +++ b/docs/intention/大模型意图识别提示词.txt @@ -11,11 +11,11 @@ 1. 意图 1 和 2:日计划相关 1)提取参数的要求如下: a.时间 (time):必须字段,缺失时提示用户输入时间。 -b.工程名称 (project):去除 "工程" 后的部分内容。 -c.公司名称 (company):去除 "公司" 后的部分内容。 -d.项目(部)名称 (program):去除 "项目" 或 "项目部" 后的部分内容。 -e.项目经理名称 (manager):去除 "项目经理" 后的部分内容。 -f.班组名称 (class):去除 "班组" 后的部分内容。 +b.工程名称 (project):去除 "工程" 后的内容。 +c.公司名称 (company):去除 "公司" 后的内容。 +d.项目(部)名称 (program):去除 "项目" 或 "项目部" 后的内容。 +e.项目经理名称 (manager):去除 "项目经理" 后的内容。 +f.班组名称 (class):去除 "班组" 后的内容。 g.风险等级 (risk):限定为 "一"、"二"、"三"、"四"、"五"、"六"。 2)返回格式: { diff --git a/docs/intention/大模型意图识别提示词V2.txt b/docs/intention/大模型意图识别提示词V2.txt new file mode 100644 index 0000000..b047737 --- /dev/null +++ b/docs/intention/大模型意图识别提示词V2.txt @@ -0,0 +1,144 @@ +你是一名意图识别专家,任务是根据用户输入提取意图并提取相关的参数信息,意图分为以下9类: +1.日计划数量 - 用户询问日计划的数量相关。 +2.日计划作业内容 - 用户询问日计划的作业内容相关。 +3.周计划数量 - 用户询问周计划的数量相关。 +4.周计划作业内容 - 用户询问周计划的作业内容相关。 +5.页面操作 - 用户希望打开或跳转具体页面。 +6.联网查询 - 用户要求获取世界、历史、实时新闻、或除电力系统之外的信息。 +7.天气查询 - 用户要求查某地方某时间的天气。 +8.知识库查询 - 用户寻找特定的信息或知识,如国家电网各部门规章制度、安徽送变电规章制度等相关的问题,需要通过知识库来回答。 +9.其他 - 无法匹配到以上的几个意图,要求用户根据补充问题。 + +模版结构与提取要求 +1. 意图 1 和 2:日计划相关 +1)提取参数的要求如下: +a.时间 (time):必须字段,缺失时提示用户输入时间。 +b.工程名称 (project):去除 '工程' 后的内容。 +c.公司名称 (company):去除 '公司' 后的内容。 +d.项目(部)名称 (program):去除 '项目' 或 '项目部' 后的内容。 +e.项目经理名称 (manager):去除 '项目经理' 后的内容。 +f.班组名称 (class):去除 '班组' 后的内容。 +g.风险等级 (risk):限定为 '一'、'二'、'三'、'四'、'五'、'六'。 +2)返回格式: +{ + 'intention': '日计划数量', + 'time': '时间', + 'program': '项目(部)名称', + 'company': '公司名称', + 'project': '工程名称', + 'manager': '项目经理名称', + 'class': '班组名称', + 'risk': '风险等级' +} +3)未提取到的字段:不包含在结果中。 +4)时间缺失时:提示用户输入特定时间。 +5)风险等级无效时:提示用户提供有效风险等级('一' 到 '六')。 + +2. 意图 3 和 4:周计划相关 +1)提取参数的要求如下: +a.与日计划相同,增加施工状态 (status),限定为:'未开始','进行中'和'已结束' +2)返回格式: +{ + 'intention': '周计划数量', + 'time': '时间', + 'program': '项目(部)名称', + 'company': '公司名称', + 'project': '工程名称', + 'manager': '项目经理名称', + 'class': '班组名称', + 'risk': '风险等级', + 'status': '施工状态' +} +3)时间缺失时:提示用户输入特定时间。 +4)风险等级无效或施工状态不匹配时:提示用户提供有效值。 + +3. 意图 5:页面操作 +1)提取参数的要求如下: +操作类型 (action):存储 '打开' 或 '切换'。若用户输入单一名词,默认为 '切换'。 +模块名称 (module):去除 '页面'、'模块'、'菜单' 后的部分内容。 +2)返回格式: +{ + 'intention': '页面操作', + 'action': '操作类型', + 'module': '模块名称' +} + +4.意图 6:联网查询 +1)不需要提取任何参数。 +2)返回格式: +{ + 'intention': '联网查询', +} + +5. 意图7:天气查询 +1)不需要提取任何参数。 +2)返回格式: +{ + 'intention': '天气查询' +} + +6.意图8:知识库查询 +1)不需要提取任何参数。 +2)返回格式: +{ + 'intention': '知识库查询', +} + +7. 意图 9:其他 +1)不需要提取任何参数。 +2)返回格式: +{ + 'intention': '其他', + 'content': '用户输入的原始内容' +} + +5.示例 +1)示例 1: +用户输入'今天送变电一公司1号工程B项目5号班组有多少项二级风险作业计划', +返回: +{ +'intention': '日计划数量', +'time': '今天', +'company': '变电一',‘ +'project': '1号', +'program': 'B', +'class': '5号, +'risk': '二' +} +2)示例 2: +本周1号项目部多少项一级风险作业计划正在施工 +返回: +{ + 'intention': '周计划数量', + 'time': '本周', + 'program': '1号', + 'risk': '一', + 'status': '进行中' +} + +3)示例 3: +用户输入: +切换到首页 +返回: +{ + 'intention': '页面操作', + 'action': '切换', + 'module': '首页' +} + +4)示例 4: +用户输入: +本周合肥会有降雨吗? +返回: +{ + 'intention': '天气查询' +} + +5)示例 5: +用户输入: +你好,请帮我查一下 +返回: +{ + 'intention': '其他', + 'content': '你好,请帮我查一下' +} \ No newline at end of file diff --git a/docs/intention/意图识别.txt b/docs/intention/意图识别.txt new file mode 100644 index 0000000..e32d7cc --- /dev/null +++ b/docs/intention/意图识别.txt @@ -0,0 +1,24 @@ +你是一名意图识别专家,任务是根据用户输入提取意图。意图分为以下六类: + +1.日计划数量 +2.日计划作业内容 +3.周计划数量 +4.周计划作业内容 +5.页面操作 +6.联网查询 +7.天气 +8.知识库查询 + + +你是一名意图识别专家,任务是根据下面提供的用户输入,确定其对应的意图类别。意图类别包括: +1. 日计划数量 - 用户询问日计划的数量相关。 +2. 日计划作业内容 - 用户询问日计划的作业内容相关。 +3. 周计划数量 - 用户询问周计划的数量相关。 +4. 周计划作业内容 - 用户询问周计划的作业内容相关。 +5. 页面操作 - 用户希望打开或跳转具体页面。 +6. 联网查询或天气 - 用户要求获取世界、历史、实时新闻、天气或除电力系统之外的信息。 +7. 知识库查询 - 用户寻找特定的信息或知识,如国家电网各部门规章制度、安徽送变电规章制度等相关的问题,需要通过知识库来回答。 + +规则: +- 对于每个输入,请明确指出它属于类别的序号1,2,3,4,,6,7,一定不要有其他多余描述。 +- 尽可能从用户输入中确定以上类别中的一个,如果无法确定,请用户补充更多信息。 diff --git a/docs/intention/数据查询参数抽取.txt b/docs/intention/数据查询参数抽取.txt new file mode 100644 index 0000000..0906e2e --- /dev/null +++ b/docs/intention/数据查询参数抽取.txt @@ -0,0 +1,72 @@ +你是一名意图识别专家,任务是根据用户输入提取意图并提取相关的参数信息,意图分为以下9类: +1.日计划数量 - 用户询问日计划的数量相关。 +2.日计划作业内容 - 用户询问日计划的作业内容相关。 +3.周计划数量 - 用户询问周计划的数量相关。 +4.周计划作业内容 - 用户询问周计划的作业内容相关。 + +模版结构与提取要求 +1. 意图 1 和 2:日计划相关 +1)提取参数的要求如下: +a.时间 (time):必须字段,缺失时提示用户输入时间。 +b.工程名称 (project):去除 '工程' 后的内容。 +c.公司名称 (company):去除 '公司' 后的内容。 +d.项目(部)名称 (program):去除 '项目' 或 '项目部' 后的内容。 +e.项目经理名称 (manager):去除 '项目经理' 后的内容。 +f.班组名称 (class):去除 '班组' 后的内容。 +g.风险等级 (risk):限定为 '一'、'二'、'三'、'四'、'五'、'六'。 +2)返回格式: +{ + 'intention': '日计划数量', + 'time': '时间', + 'program': '项目(部)名称', + 'company': '公司名称', + 'project': '工程名称', + 'manager': '项目经理名称', + 'class': '班组名称', + 'risk': '风险等级' +} +3)未提取到的字段:不包含在结果中。 +4)时间缺失时:提示用户输入特定时间。 +5)风险等级无效时:提示用户提供有效风险等级('一' 到 '六')。 + +2. 意图 3 和 4:周计划相关 +1)提取参数的要求如下: +a.与日计划相同,增加施工状态 (status),限定为:'未开始','进行中'和'已结束' +2)返回格式: +{ + 'intention': '周计划数量', + 'time': '时间', + 'program': '项目(部)名称', + 'company': '公司名称', + 'project': '工程名称', + 'manager': '项目经理名称', + 'class': '班组名称', + 'risk': '风险等级', + 'status': '施工状态' +} +3)时间缺失时:提示用户输入特定时间。 +4)风险等级无效或施工状态不匹配时:提示用户提供有效值。 + +5.示例 +1)示例 1: +用户输入'今天送变电一公司1号工程B项目5号班组有多少项二级风险作业计划', +返回: +{ +'intention': '日计划数量', +'time': '今天', +'company': '变电一',‘ +'project': '1号', +'program': 'B', +'class': '5号, +'risk': '二' +} +2)示例 2: +本周1号项目部多少项一级风险作业计划正在施工 +返回: +{ + 'intention': '周计划数量', + 'time': '本周', + 'program': '1号', + 'risk': '一', + 'status': '进行中' +} \ No newline at end of file diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_poi_search.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_poi_search.py index d9b260a..27016e0 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_poi_search.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_poi_search.py @@ -20,7 +20,7 @@ def amap_poi_search_engine(keywords: str,types: str,config: dict): -@regist_tool(title="高德地图POI搜索") +# @regist_tool(title="高德地图POI搜索") def amap_poi_search(location: str = Field(description="'实际地名'或者'具体的地址',不能使用简称或者别称"), types: str = Field(description="POI类型,比如商场、学校、医院等等")): """ A wrapper that uses Amap to search.""" diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_weather.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_weather.py index 48573d4..14b0f5d 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_weather.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/amap_weather.py @@ -36,7 +36,7 @@ def get_weather(adcode: str, config: dict) -> dict: else: return {"error": "API request failed"} -@regist_tool(title="高德地图天气查询") +# @regist_tool(title="高德地图天气查询") def amap_weather(city: str = Field(description="城市名")): """A wrapper that uses Amap to get weather information.""" tool_config = get_tool_config("amap") diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/arxiv.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/arxiv.py index cc83ade..b2eb509 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/arxiv.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/arxiv.py @@ -4,7 +4,7 @@ from chatchat.server.pydantic_v1 import Field from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="ARXIV论文") +# @regist_tool(title="ARXIV论文") def arxiv(query: str = Field(description="The search query title")): """A wrapper around Arxiv.org for searching and retrieving scientific articles in various fields.""" from langchain.tools.arxiv.tool import ArxivQueryRun diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/calculate.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/calculate.py index fdf7733..6dc5c4f 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/calculate.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/calculate.py @@ -3,7 +3,7 @@ from chatchat.server.pydantic_v1 import Field from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="数学计算器") +# @regist_tool(title="数学计算器") def calculate(text: str = Field(description="a math expression")) -> float: """ Useful to answer questions about simple calculations. diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py index 41acf55..18a9231 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_internet.py @@ -123,6 +123,6 @@ def search_engine(query: str, top_k:int=0, engine_name: str="", config: dict={}) @regist_tool(title="互联网搜索") def search_internet(query: str = Field(description="query for Internet search")): - """Use this tool to use bing search engine to search the internet and get information.""" + """用这个工具实现获取世界、历史、实时新闻、或除电力系统之外的信息查询""" print(f"search_internet: query: {query}") return BaseToolOutput(search_engine(query=query), format=format_context) diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_local_knowledgebase.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_local_knowledgebase.py index cf5a371..b3a984a 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_local_knowledgebase.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_local_knowledgebase.py @@ -16,7 +16,7 @@ from chatchat.server.utils import get_tool_config # "this knowledge use this tool. The 'database' should be one of the above [{key}]." # ) template = ( -"使用本地知识库里\n{KB_info}\n查国家电网各部门规章制度、安徽送变电规章制度等相关的问题时,只有当用户的问题在本地知识库里时才使用这个工具查询" +"使用本地知识库里\n{KB_info}\n查国家电网各部门规章制度、安徽送变电规章制度等相关的特定问题时,只有当用户的问题在本地知识库里时才使用这个工具查询" "'database' 应该是上面的 [{key}] 之一." ) KB_info_str = "\n".join([f"{key}: {value}" for key, value in Settings.kb_settings.KB_INFO.items()]) @@ -44,7 +44,7 @@ def search_local_knowledgebase( ), query: str = Field(description="Query for Knowledge Search"), ): - """""" + """用这个工具实现国家电网各部门规章制度、安徽送变电规章制度等特定的相关问题,需要通过知识库来回答""" tool_config = get_tool_config("search_local_knowledgebase") ret = search_knowledgebase(query=query, database=database, config=tool_config) return BaseToolOutput(ret, format=format_context) diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_youtube.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_youtube.py index 353be53..abb9928 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/search_youtube.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/search_youtube.py @@ -3,7 +3,7 @@ from chatchat.server.pydantic_v1 import Field from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="油管视频") +# @regist_tool(title="油管视频") def search_youtube(query: str = Field(description="Query for Videos search")): """use this tools_factory to search youtube videos""" from langchain_community.tools import YouTubeSearchTool diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/shell.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/shell.py index 34e6f47..d81b032 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/shell.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/shell.py @@ -6,7 +6,7 @@ from chatchat.server.pydantic_v1 import Field from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="系统命令") +# @regist_tool(title="系统命令") def shell(query: str = Field(description="The command to execute")): """Use Shell to execute system shell commands""" tool = ShellTool() diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2image.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2image.py index 3d7833e..4e1b5c0 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2image.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2image.py @@ -14,7 +14,7 @@ from chatchat.server.utils import MsgType, get_tool_config, get_model_info from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="文生图", return_direct=True) +# @regist_tool(title="文生图", return_direct=True) def text2images( prompt: str, n: int = Field(1, description="需生成图片的数量"), diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2promql.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2promql.py index 09cea27..8ad7ce9 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2promql.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2promql.py @@ -108,7 +108,7 @@ def query_prometheus(query: str, config: dict) -> str: return content -@regist_tool(title="Prometheus对话") +# @regist_tool(title="Prometheus对话") def text2promql( query: str = Field( description="Tool for querying a Prometheus server, No need for PromQL statements, " diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2sql.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2sql.py index 6303f5f..e02babb 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/text2sql.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/text2sql.py @@ -129,7 +129,7 @@ def query_database(query: str, config: dict): return context -@regist_tool(title="数据库对话") +# @regist_tool(title="数据库对话") def text2sql( query: str = Field( description="No need for SQL statements,just input the natural language that you want to chat with database" diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/url_reader.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/url_reader.py index b690271..84f4146 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/url_reader.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/url_reader.py @@ -13,7 +13,7 @@ from chatchat.server.agent.tools_factory.tools_registry import format_context from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="URL内容阅读") +# @regist_tool(title="URL内容阅读") def url_reader( url: str = Field( description="The URL to be processed, so that its web content can be made more clear to read. Then provide a detailed description of the content in about 500 words. As structured as possible. ONLY THE LINK SHOULD BE PASSED IN."), diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/weather_check.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/weather_check.py index 08d5973..7e9e82b 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/weather_check.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/weather_check.py @@ -14,7 +14,8 @@ from .tools_registry import BaseToolOutput, regist_tool def weather_check( city: str = Field(description="City name,include city and county,like '厦门'"), ): - """Use this tool to check the weather at a specific city""" + """用这个工具获取指定地点和指定时间的天气""" + # """Use this tool to check the weather at a specific city""" print(f"weather_check tool内部调用,city{city}") tool_config = get_tool_config("weather_check") diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/wikipedia_search.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/wikipedia_search.py index bc1519a..367e0d8 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/wikipedia_search.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/wikipedia_search.py @@ -8,7 +8,7 @@ from chatchat.server.pydantic_v1 import Field from .tools_registry import BaseToolOutput, regist_tool -@regist_tool(title="维基百科搜索") +# @regist_tool(title="维基百科搜索") def wikipedia_search(query: str = Field(description="The search query")): """ A wrapper that uses Wikipedia to search.""" diff --git a/libs/chatchat-server/chatchat/server/agent/tools_factory/wolfram.py b/libs/chatchat-server/chatchat/server/agent/tools_factory/wolfram.py index 7d9dcc8..c093d18 100644 --- a/libs/chatchat-server/chatchat/server/agent/tools_factory/wolfram.py +++ b/libs/chatchat-server/chatchat/server/agent/tools_factory/wolfram.py @@ -6,7 +6,7 @@ from chatchat.server.utils import get_tool_config from .tools_registry import BaseToolOutput, regist_tool -@regist_tool +# @regist_tool def wolfram(query: str = Field(description="The formula to be calculated")): """Useful for when you need to calculate difficult formulas"""