优化添加文件时,前后端的报错

This commit is contained in:
Wenjie Zhang 2025-04-24 22:55:10 +08:00
parent 14dfe60333
commit aebad0ae5d
2 changed files with 15 additions and 6 deletions

View File

@ -171,11 +171,15 @@ async def get_graph_nodes(kgdb_name: str, num: int):
@data.post("/graph/add-by-jsonl") @data.post("/graph/add-by-jsonl")
async def add_graph_entity(file_path: str = Body(...), kgdb_name: Optional[str] = Body(None)): async def add_graph_entity(file_path: str = Body(...), kgdb_name: Optional[str] = Body(None)):
if not config.enable_knowledge_graph: if not config.enable_knowledge_graph:
raise HTTPException(status_code=400, detail="Knowledge graph is not enabled") return {"message": "知识图谱未启用", "status": "failed"}
if not file_path.endswith('.jsonl'): if not file_path.endswith('.jsonl'):
raise HTTPException(status_code=400, detail="file_path must be a jsonl file") return {"message": "文件格式错误请上传jsonl文件", "status": "failed"}
await graph_base.jsonl_file_add_entity(file_path, kgdb_name) try:
return {"message": "Entity successfully added"} await graph_base.jsonl_file_add_entity(file_path, kgdb_name)
return {"message": "实体添加成功", "status": "success"}
except Exception as e:
logger.error(f"添加实体失败: {e}, {traceback.format_exc()}")
return {"message": f"添加实体失败: {e}", "status": "failed"}

View File

@ -198,10 +198,15 @@ const addDocumentByFile = () => {
}) })
.then(response => response.json()) .then(response => response.json())
.then((data) => { .then((data) => {
message.success(data.message); if (data.status === 'success') {
state.showModal = false; message.success(data.message);
state.showModal = false;
} else {
throw new Error(data.message);
}
}) })
.catch((error) => { .catch((error) => {
console.error(error)
message.error(error.message); message.error(error.message);
}) })
.finally(() => state.precessing = false) .finally(() => state.precessing = false)