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