|
@@ -589,30 +589,30 @@ async def process_request_background(request_id: str):
|
|
|
extraction_requests: set = set()
|
|
|
|
|
|
@app.post("/extract")
|
|
|
-async def extract(request_id: str, query_word: str):
|
|
|
+async def extract(requestId: str, query: str):
|
|
|
try:
|
|
|
# 检查请求是否已经在处理中
|
|
|
async with RUNNING_LOCK:
|
|
|
- if request_id in extraction_requests:
|
|
|
- return {"status": 1, "request_id": request_id, "message": "请求已在处理中"}
|
|
|
- extraction_requests.add(request_id)
|
|
|
+ if requestId in extraction_requests:
|
|
|
+ return {"status": 1, "request_id": requestId, "message": "请求已在处理中"}
|
|
|
+ extraction_requests.add(requestId)
|
|
|
|
|
|
try:
|
|
|
# 更新状态为处理中
|
|
|
- update_extract_status(request_id, 1)
|
|
|
+ update_extract_status(requestId, 1)
|
|
|
# 执行Agent
|
|
|
- result = execute_agent_with_api(json.dumps({"query_word":query_word, "request_id": request_id}))
|
|
|
+ result = execute_agent_with_api(json.dumps({"query_word":query, "request_id": requestId}))
|
|
|
finally:
|
|
|
# 无论成功失败,都从运行集合中移除
|
|
|
async with RUNNING_LOCK:
|
|
|
- extraction_requests.discard(request_id)
|
|
|
+ extraction_requests.discard(requestId)
|
|
|
except Exception as e:
|
|
|
# 发生异常,更新状态为处理失败
|
|
|
- update_request_status(request_id, 3)
|
|
|
+ update_extract_status(requestId, 3)
|
|
|
raise HTTPException(status_code=500, detail=f"执行Agent时出错: {str(e)}")
|
|
|
|
|
|
@app.post("/expand")
|
|
|
-async def expand(request: ExpandRequest, background_tasks: BackgroundTasks):
|
|
|
+async def expand(request: ExpandRequest, query: str, background_tasks: BackgroundTasks):
|
|
|
"""
|
|
|
执行扩展查询处理
|
|
|
|
|
@@ -624,16 +624,14 @@ async def expand(request: ExpandRequest, background_tasks: BackgroundTasks):
|
|
|
dict: 包含执行状态的字典
|
|
|
"""
|
|
|
try:
|
|
|
- requestId = request.requestId
|
|
|
-
|
|
|
# 立即更新状态为处理中
|
|
|
- _update_expansion_status(requestId, 1)
|
|
|
+ _update_expansion_status(request.requestId, 1)
|
|
|
|
|
|
# 添加后台任务
|
|
|
- background_tasks.add_task(execute_expand_agent_with_api, requestId)
|
|
|
+ background_tasks.add_task(execute_expand_agent_with_api, request.requestId, query)
|
|
|
|
|
|
# 立即返回状态
|
|
|
- return {"status": 1, "requestId": requestId, "message": "扩展查询处理已启动"}
|
|
|
+ return {"status": 1, "requestId": request.requestId, "message": "扩展查询处理已启动"}
|
|
|
|
|
|
except Exception as e:
|
|
|
raise HTTPException(status_code=500, detail=f"执行Agent时出错: {str(e)}")
|