|
@@ -19,17 +19,22 @@ nest_asyncio.apply()
|
|
|
|
|
|
class FileSearchToolInput(BaseModel):
|
|
|
# query: str = Field(..., description="query to look up in retrieval")
|
|
|
- query: str = Field(description="search query to look up")
|
|
|
+ query: str = Field(
|
|
|
+ description="Search term (keyword) or natural language query for semantic search."
|
|
|
+ )
|
|
|
|
|
|
|
|
|
class FileSearchTool(BaseTool):
|
|
|
name: str = "file_search"
|
|
|
description: str = (
|
|
|
+ "Search files by keyword, content, or semantic similarity. Returns file paths and relevant snippets for RAG."
|
|
|
+ """
|
|
|
"Can be used to look up information that was uploaded to this assistant."
|
|
|
"If the user is referencing particular files, that is often a good hint that information may be here."
|
|
|
"A search engine optimized for comprehensive, accurate, and trusted results. "
|
|
|
"Useful for when you need to answer questions about current events. "
|
|
|
"Input should be a search query."
|
|
|
+ """
|
|
|
)
|
|
|
|
|
|
args_schema: Type[BaseModel] = FileSearchToolInput
|
|
@@ -142,22 +147,27 @@ class FileSearchTool(BaseTool):
|
|
|
"""
|
|
|
为 Retrieval 提供文件选择信息,用于 llm 调用抉择
|
|
|
"""
|
|
|
- return (
|
|
|
- "## 工具使用规范"
|
|
|
- + "可调用工具:"
|
|
|
- + "- retrieval:用于在文件库中搜索与问题相关的具体内容"
|
|
|
- + "**调用规则**:"
|
|
|
- + "1. 当问题涉及以下情况时必须调用本工具:"
|
|
|
- + " - 询问文件/文档中的具体内容"
|
|
|
- + " - 需要查找数据、条款或技术细节"
|
|
|
- + ' - 用户明确要求"查文件"或"搜索资料"'
|
|
|
- + "2. 调用时需遵循:"
|
|
|
- + " ```json"
|
|
|
- + " {"
|
|
|
- + ' "action": "retrieval",'
|
|
|
- + ' "action_input": {'
|
|
|
- + ' "query": "精炼后的搜索语句,需包含至少2个关键要素(用户问题的原始上下文)"'
|
|
|
- + " }"
|
|
|
- + " }"
|
|
|
- )
|
|
|
+ if (self.__keys and len(self.__keys) > 0) or (
|
|
|
+ self.__dirkeys and len(self.__dirkeys) > 0
|
|
|
+ ):
|
|
|
+ return (
|
|
|
+ "## 工具使用规范"
|
|
|
+ + "可调用工具:"
|
|
|
+ + "- file_search:用于在文件库中搜索与问题相关的具体内容"
|
|
|
+ + "**调用规则**:"
|
|
|
+ + "1. 当问题涉及以下情况时必须调用本工具:"
|
|
|
+ + " - 询问文件/文档中的具体内容"
|
|
|
+ + " - 需要查找数据、条款或技术细节"
|
|
|
+ + ' - 用户明确要求"查文件"或"搜索资料"'
|
|
|
+ + "2. 调用时需遵循:"
|
|
|
+ + " ```json"
|
|
|
+ + " {"
|
|
|
+ + ' "action": "retrieval",'
|
|
|
+ + ' "action_input": {'
|
|
|
+ + ' "query": "精炼后的搜索语句,需包含至少多个关键要素的一句话(用户问题的原始上下文)"'
|
|
|
+ + " }"
|
|
|
+ + " }"
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ return ""
|
|
|
# return '## important:You can use the "retrieval" tool to search for relevant information.\n If you are asking about the content of the files, please specify any keywords, topics, or context you are looking for to help retrieve the most relevant content.'
|