Update get_knowledge.py

pull/998/head
2829798842 2025-05-28 19:15:09 +08:00 committed by GitHub
parent d15091c2c6
commit 5780765cb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -13,12 +13,12 @@ class SearchKnowledgeTool(BaseTool):
"""从知识库中搜索相关信息的工具"""
name = "search_knowledge"
description = "使用工具从知识库中搜索相关信息"
description = "Use tool to search relevant information from the knowledge base"
parameters = {
"type": "object",
"properties": {
"query": {"type": "string", "description": "搜索查询关键词"},
"threshold": {"type": "number", "description": "相似度阈值0.0到1.0之间"},
"query": {"type": "string", "description": "Search query keywords"},
"threshold": {"type": "number", "description": "Similarity threshold, between 0.0 and 1.0"},
},
"required": ["query"],
}
@ -42,14 +42,14 @@ class SearchKnowledgeTool(BaseTool):
if embedding:
knowledge_info = self.get_info_from_db(embedding, limit=3, threshold=threshold)
if knowledge_info:
content = f"你知道这些知识: {knowledge_info}"
content = f"You know this knowledge: {knowledge_info}"
else:
content = f"你不太了解有关{query}的知识"
content = f"You don't know much about {query}"
return {"type": "knowledge", "id": query, "content": content}
return {"type": "info", "id": query, "content": f"无法获取关于'{query}'的嵌入向量,你知识库炸了"}
return {"type": "info", "id": query, "content": f"Unable to get embedding vector for '{query}', knowledge base failed"}
except Exception as e:
logger.error(f"知识库搜索工具执行失败: {str(e)}")
return {"type": "info", "id": query, "content": f"知识库搜索失败,炸了: {str(e)}"}
logger.error(f"Knowledge base search tool execution failed: {str(e)}")
return {"type": "info", "id": query, "content": f"Knowledge base search failed: {str(e)}"}
@staticmethod
def _cosine_similarity(vec1: List[float], vec2: List[float]) -> float: