新增v3接口
This commit is contained in:
38
backend/routers/v3.py
Normal file
38
backend/routers/v3.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
from fastapi import APIRouter, BackgroundTasks
|
||||||
|
from backend.services.crawler_service import crawler_service
|
||||||
|
from backend.utils.common import make_response
|
||||||
|
from backend.schemas.schemas import AutoMapRequest, AutoProcessRequest, TextSearchRequest
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/api/v3", tags=["V3 Service"])
|
||||||
|
|
||||||
|
@router.post("/add_task")
|
||||||
|
async def add_task(req: AutoMapRequest):
|
||||||
|
try:
|
||||||
|
res = crawler_service.map_site(req.url)
|
||||||
|
return make_response(1, res.pop("msg", "Started"), res)
|
||||||
|
except Exception as e:
|
||||||
|
return make_response(0, str(e))
|
||||||
|
|
||||||
|
@router.post("/process_task")
|
||||||
|
async def auto_process(req: AutoProcessRequest, bg_tasks: BackgroundTasks):
|
||||||
|
try:
|
||||||
|
bg_tasks.add_task(crawler_service.process_queue, req.task_id, req.batch_size)
|
||||||
|
return make_response(1, "Background processing started", {"task_id": req.task_id})
|
||||||
|
except Exception as e:
|
||||||
|
return make_response(0, str(e))
|
||||||
|
|
||||||
|
@router.post("/task_status")
|
||||||
|
async def get_task_status(req):
|
||||||
|
try:
|
||||||
|
res = crawler_service.get_task_status(req.task_id)
|
||||||
|
return make_response(1, res.pop("msg", "Success"), res)
|
||||||
|
except Exception as e:
|
||||||
|
return make_response(0, str(e))
|
||||||
|
pass
|
||||||
|
@router.post("/search")
|
||||||
|
async def search_smart(req: TextSearchRequest):
|
||||||
|
try:
|
||||||
|
res = crawler_service.search(req.query, req.task_id, req.return_num)
|
||||||
|
return make_response(1, res.pop("msg", "Success"), res)
|
||||||
|
except Exception as e:
|
||||||
|
return make_response(0, str(e))
|
||||||
@@ -16,8 +16,6 @@
|
|||||||
- [ ] 添加任务
|
- [ ] 添加任务
|
||||||
- [ ] 查询任务
|
- [ ] 查询任务
|
||||||
- [ ] 执行任务
|
- [ ] 执行任务
|
||||||
- [ ] 获取任务状态
|
|
||||||
- [ ] 获取任务结果
|
|
||||||
- [ ] 知识库搜索
|
- [ ] 知识库搜索
|
||||||
2. 包装成MCP
|
2. 包装成MCP
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user