28 lines
858 B
Python
28 lines
858 B
Python
"""
|
|||
|
|
知识库自动更新 API
|
||
|
|
==================
|
||
|
|
|
||
|
|
【功能说明】手动触发知识库自动更新、查看更新状态。
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
from fastapi import APIRouter
|
||
|
|
|
||
|
|
from app.schemas.project import ApiResponse
|
||
|
|
from app.services.knowledge_autoupdate import check_and_update
|
||
|
|
|
||
|
|
logger = logging.getLogger("agent.knowledge_autoupdate.api")
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/api/knowledge", tags=["知识库管理"])
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/auto-update", response_model=ApiResponse[dict], summary="自动更新知识库")
|
||
|
|
def auto_update() -> ApiResponse[dict]:
|
||
|
|
"""检查素材目录变更并自动更新知识库(增量/全量)。"""
|
||
|
|
result = check_and_update()
|
||
|
|
code = 0 if "失败" not in result.get("message", "") else 1
|
||
|
|
return ApiResponse(code=code, message=result.get("message", "完成"), data=result)
|