fixed file uploading

This commit is contained in:
Saifeddine ALOUI
2024-12-26 22:48:52 +01:00
parent f2b52a2a38
commit 5fcfb05e62
4 changed files with 19 additions and 19 deletions

View File

@@ -339,11 +339,11 @@ def create_app(args):
@app.post("/documents/text", response_model=InsertResponse)
async def insert_text(request: InsertTextRequest):
try:
rag.insert(request.text)
await rag.ainsert(request.text)
return InsertResponse(
status="success",
message="Text successfully inserted",
document_count=len(rag),
document_count=1,
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@@ -365,7 +365,7 @@ def create_app(args):
return InsertResponse(
status="success",
message=f"File '{file.filename}' successfully inserted",
document_count=len(rag),
document_count=1,
)
except UnicodeDecodeError:
raise HTTPException(status_code=400, detail="File encoding not supported")
@@ -397,7 +397,7 @@ def create_app(args):
return InsertResponse(
status="success" if inserted_count > 0 else "partial_success",
message=status_message,
document_count=len(rag),
document_count=len(files),
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View File

@@ -219,7 +219,7 @@ def create_app(args):
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
rag.insert(content)
await rag.ainsert(content)
doc_manager.mark_as_indexed(file_path)
indexed_count += 1
except Exception as e:
@@ -250,7 +250,7 @@ def create_app(args):
# Immediately index the uploaded file
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
rag.insert(content)
await rag.ainsert(content)
doc_manager.mark_as_indexed(file_path)
return {
@@ -313,7 +313,7 @@ def create_app(args):
if file.filename.endswith((".txt", ".md")):
text = content.decode("utf-8")
rag.insert(text)
await rag.ainsert(text)
else:
raise HTTPException(
status_code=400,
@@ -323,7 +323,7 @@ def create_app(args):
return InsertResponse(
status="success",
message=f"File '{file.filename}' successfully inserted",
document_count=len(rag),
document_count=1,
)
except UnicodeDecodeError:
raise HTTPException(status_code=400, detail="File encoding not supported")
@@ -341,7 +341,7 @@ def create_app(args):
content = await file.read()
if file.filename.endswith((".txt", ".md")):
text = content.decode("utf-8")
rag.insert(text)
await rag.ainsert(text)
inserted_count += 1
else:
failed_files.append(f"{file.filename} (unsupported type)")
@@ -355,7 +355,7 @@ def create_app(args):
return InsertResponse(
status="success" if inserted_count > 0 else "partial_success",
message=status_message,
document_count=len(rag),
document_count=len(files),
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View File

@@ -219,7 +219,7 @@ def create_app(args):
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
rag.insert(content)
await rag.ainsert(content)
doc_manager.mark_as_indexed(file_path)
indexed_count += 1
except Exception as e:
@@ -250,7 +250,7 @@ def create_app(args):
# Immediately index the uploaded file
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
rag.insert(content)
await rag.ainsert(content)
doc_manager.mark_as_indexed(file_path)
return {
@@ -297,7 +297,7 @@ def create_app(args):
@app.post("/documents/text", response_model=InsertResponse)
async def insert_text(request: InsertTextRequest):
try:
rag.insert(request.text)
await rag.ainsert(request.text)
return InsertResponse(
status="success",
message="Text successfully inserted",
@@ -313,7 +313,7 @@ def create_app(args):
if file.filename.endswith((".txt", ".md")):
text = content.decode("utf-8")
rag.insert(text)
await rag.ainsert(text)
else:
raise HTTPException(
status_code=400,
@@ -323,7 +323,7 @@ def create_app(args):
return InsertResponse(
status="success",
message=f"File '{file.filename}' successfully inserted",
document_count=len(rag),
document_count=1,
)
except UnicodeDecodeError:
raise HTTPException(status_code=400, detail="File encoding not supported")
@@ -341,7 +341,7 @@ def create_app(args):
content = await file.read()
if file.filename.endswith((".txt", ".md")):
text = content.decode("utf-8")
rag.insert(text)
await rag.ainsert(text)
inserted_count += 1
else:
failed_files.append(f"{file.filename} (unsupported type)")
@@ -355,7 +355,7 @@ def create_app(args):
return InsertResponse(
status="success" if inserted_count > 0 else "partial_success",
message=status_message,
document_count=len(rag),
document_count=len(files),
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View File

@@ -327,7 +327,7 @@ def create_app(args):
return InsertResponse(
status="success",
message=f"File '{file.filename}' successfully inserted",
document_count=len(rag),
document_count=1,
)
except UnicodeDecodeError:
raise HTTPException(status_code=400, detail="File encoding not supported")
@@ -359,7 +359,7 @@ def create_app(args):
return InsertResponse(
status="success" if inserted_count > 0 else "partial_success",
message=status_message,
document_count=len(rag),
document_count=len(files),
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))