修改document_app.py的upload

This commit is contained in:
2025-10-28 16:28:41 +08:00
parent cbe0477ba1
commit d174de94b6

View File

@@ -89,7 +89,7 @@ class RemoveDocumentRequest(BaseModel):
class RunDocumentRequest(BaseModel): class RunDocumentRequest(BaseModel):
doc_ids: List[str] doc_ids: List[str]
run: str run: int
delete: bool = False delete: bool = False
class RenameDocumentRequest(BaseModel): class RenameDocumentRequest(BaseModel):
@@ -182,17 +182,17 @@ router = APIRouter()
@router.post("/upload") @router.post("/upload")
async def upload( async def upload(
kb_id: str = Form(...), kb_id: str = Form(...),
files: List[UploadFile] = File(...), file: List[UploadFile] = File(...),
current_user = Depends(get_current_user) current_user = Depends(get_current_user)
): ):
if not kb_id: if not kb_id:
return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR) return get_json_result(data=False, message='Lack of "KB ID"', code=settings.RetCode.ARGUMENT_ERROR)
if not files: if not file:
return get_json_result(data=False, message="No file part!", code=settings.RetCode.ARGUMENT_ERROR) return get_json_result(data=False, message="No file part!", code=settings.RetCode.ARGUMENT_ERROR)
# Use UploadFile directly # Use UploadFile directly - file is already a list from multiple file fields
file_objs = files file_objs = file
for file_obj in file_objs: for file_obj in file_objs:
if file_obj.filename == "": if file_obj.filename == "":
@@ -580,7 +580,7 @@ async def run(
kb_table_num_map = {} kb_table_num_map = {}
for id in req.doc_ids: for id in req.doc_ids:
info = {"run": str(req.run), "progress": 0} info = {"run": str(req.run), "progress": 0}
if str(req.run) == TaskStatus.RUNNING.value and req.delete: if req.run == int(TaskStatus.RUNNING.value) and req.delete:
info["progress_msg"] = "" info["progress_msg"] = ""
info["chunk_num"] = 0 info["chunk_num"] = 0
info["token_num"] = 0 info["token_num"] = 0
@@ -592,12 +592,12 @@ async def run(
if not e: if not e:
return get_data_error_result(message="Document not found!") return get_data_error_result(message="Document not found!")
if str(req.run) == TaskStatus.CANCEL.value: if req.run == int(TaskStatus.CANCEL.value):
if str(doc.run) == TaskStatus.RUNNING.value: if str(doc.run) == TaskStatus.RUNNING.value:
cancel_all_task_of(id) cancel_all_task_of(id)
else: else:
return get_data_error_result(message="Cannot cancel a task that is not in RUNNING status") return get_data_error_result(message="Cannot cancel a task that is not in RUNNING status")
if all([req.delete, str(req.run) == TaskStatus.RUNNING.value, str(doc.run) == TaskStatus.DONE.value]): if all([req.delete, req.run == int(TaskStatus.RUNNING.value), str(doc.run) == TaskStatus.DONE.value]):
DocumentService.clear_chunk_num_when_rerun(doc.id) DocumentService.clear_chunk_num_when_rerun(doc.id)
DocumentService.update_by_id(id, info) DocumentService.update_by_id(id, info)
@@ -606,7 +606,7 @@ async def run(
if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id): if settings.docStoreConn.indexExist(search.index_name(tenant_id), doc.kb_id):
settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), doc.kb_id) settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), doc.kb_id)
if str(req.run) == TaskStatus.RUNNING.value: if req.run == int(TaskStatus.RUNNING.value):
doc = doc.to_dict() doc = doc.to_dict()
doc["tenant_id"] = tenant_id doc["tenant_id"] = tenant_id