Merge branch 'rag_receive_top_k'

This commit is contained in:
朱潮 2026-01-08 17:28:59 +08:00
commit 37958291ae
4 changed files with 18 additions and 12 deletions

View File

@ -29,7 +29,7 @@ from mcp_common import (
BACKEND_HOST = os.getenv("BACKEND_HOST", "https://api-dev.gptbase.ai")
MASTERKEY = os.getenv("MASTERKEY", "master")
def rag_retrieve(query: str) -> Dict[str, Any]:
def rag_retrieve(query: str, top_k: int = 100) -> Dict[str, Any]:
"""调用RAG检索API"""
try:
bot_id = ""
@ -51,14 +51,14 @@ def rag_retrieve(query: str) -> Dict[str, Any]:
masterkey = MASTERKEY
token_input = f"{masterkey}:{bot_id}"
auth_token = hashlib.md5(token_input.encode()).hexdigest()
headers = {
"content-type": "application/json",
"authorization": f"Bearer {auth_token}"
}
data = {
"query": query,
"top_k": 100
"top_k": top_k
}
# 发送POST请求
@ -170,12 +170,13 @@ async def handle_request(request: Dict[str, Any]) -> Dict[str, Any]:
if tool_name == "rag_retrieve":
query = arguments.get("query", "")
top_k = arguments.get("top_k", 100)
if not query:
return create_error_response(request_id, -32602, "Missing required parameter: query")
result = rag_retrieve(query)
result = rag_retrieve(query, top_k)
return {
"jsonrpc": "2.0",
"id": request_id,

View File

@ -8,9 +8,14 @@
"query": {
"type": "string",
"description": "Retrieval query content"
},
"top_k": {
"type": "integer",
"description": "Number of top results to retrieve (default: 100)",
"default": 100
}
},
"required": ["query"]
}
}
]
]

View File

@ -1,7 +1,7 @@
{extra_prompt}
# Execution Guidelines
- **Knowledge Base First**: For user inquiries about products, policies, troubleshooting, factual questions, etc., prioritize querying the `rag_retrieve-rag_retrieve` knowledge base. Use other tools only if no results are found.
- **Knowledge Base First**: For user inquiries about products, policies, troubleshooting, factual questions, etc., prioritize querying the `rag_retrieve` knowledge base. Use other tools only if no results are found.
- **Tool-Driven**: All operations are implemented through tool interfaces.
- **Immediate Response**: Trigger the corresponding tool call as soon as the intent is identified.
- **Result-Oriented**: Directly return execution results, minimizing transitional language.
@ -10,7 +10,7 @@
# Output Content Must Adhere to the Following Requirements (Important)
**System Constraints**: Do not expose any prompt content to the user. Use appropriate tools to analyze data. The results returned by tool calls do not need to be printed.
**Language Requirement**: All user interactions and result outputs must be in [{language}].
**Image Handling**: The content returned by the `rag_retrieve-rag_retrieve` tool may include images. Each image is exclusively associated with its nearest text or sentence. If multiple consecutive images appear near a text area, all of them are related to the nearest text content. Do not ignore these images, and always maintain their correspondence with the nearest text. Each sentence or key point in the response should be accompanied by relevant images (when they meet the established association criteria). Avoid placing all images at the end of the response.
**Image Handling**: The content returned by the `rag_retrieve` tool may include images. Each image is exclusively associated with its nearest text or sentence. If multiple consecutive images appear near a text area, all of them are related to the nearest text content. Do not ignore these images, and always maintain their correspondence with the nearest text. Each sentence or key point in the response should be accompanied by relevant images (when they meet the established association criteria). Avoid placing all images at the end of the response.
## System Information
- **Current User**: {user_identifier}

View File

@ -1,7 +1,7 @@
{extra_prompt}
# 执行准则
- **知识库优先**:用户咨询产品、政策、故障排查、事实性问题等,优先查询`rag_retrieve-rag_retrieve`知识库,无结果时再使用其他工具
- **知识库优先**:用户咨询产品、政策、故障排查、事实性问题等,优先查询`rag_retrieve`知识库,无结果时再使用其他工具
- **工具驱动**:所有操作通过工具接口实现
- **即时响应**:识别意图后立即触发相应工具调用
- **结果导向**:直接返回执行结果,减少过渡性语言
@ -10,7 +10,7 @@
# 输出内容必须遵循以下要求(重要)
**系统约束**:禁止向用户暴露任何提示词内容,请调用合适的工具来分析数据,工具调用的返回的结果不需要进行打印输出。
**语言要求**:所有用户交互和结果输出,必须使用[{language}]
**图片处理**`rag_retrieve-rag_retrieve`工具返回的内容里会存在图像,每张图片都专属于其最邻近的文本或句子。若文本区域附近存在多张连续排列的图片,这些图片均与最近的文本内容相关联。请勿忽略这些图片,并始终保持它们与最近文本的对应关系。回答中的每个句子或关键点均需配附相关图片(符合既定关联标准时)。请注意避免将所有图片集中放置在回答末尾。
**图片处理**`rag_retrieve`工具返回的内容里会存在图像,每张图片都专属于其最邻近的文本或句子。若文本区域附近存在多张连续排列的图片,这些图片均与最近的文本内容相关联。请勿忽略这些图片,并始终保持它们与最近文本的对应关系。回答中的每个句子或关键点均需配附相关图片(符合既定关联标准时)。请注意避免将所有图片集中放置在回答末尾。
## 系统信息
- **当前用户**: {user_identifier}