muhammad1707 commited on
Commit
e93cc31
·
1 Parent(s): 772f141

added reset endpoint

Browse files
Files changed (1) hide show
  1. back/server.py +29 -0
back/server.py CHANGED
@@ -14,6 +14,7 @@ from fastapi.middleware.cors import CORSMiddleware
14
  from fastapi.staticfiles import StaticFiles
15
  from fastapi.responses import FileResponse
16
  from pydantic import BaseModel
 
17
 
18
  # ==============================
19
  # 0. Sozlamalar
@@ -784,6 +785,34 @@ async def serve_spa(full_path: str):
784
  return FileResponse(index_file)
785
  raise HTTPException(status_code=404, detail="Frontend build not found")
786
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
  # ==============================
788
  # 16. SERVER STARTUP
789
  # ==============================
 
14
  from fastapi.staticfiles import StaticFiles
15
  from fastapi.responses import FileResponse
16
  from pydantic import BaseModel
17
+ import shutil
18
 
19
  # ==============================
20
  # 0. Sozlamalar
 
785
  return FileResponse(index_file)
786
  raise HTTPException(status_code=404, detail="Frontend build not found")
787
 
788
+ ######################################################
789
+ # RESET CHROMA DB RESET CHATS DB REMOVE UPLOADS FILES
790
+
791
+ @app.post("/admin/reset-rag")
792
+ async def reset_rag():
793
+ base_dir = Path(__file__).resolve().parent
794
+ chroma_dir = base_dir / "chroma_db"
795
+ chats_db = base_dir / "chats.db"
796
+ uploads_dir = base_dir / "data" / "uploads"
797
+
798
+ try:
799
+ if chroma_dir.exists():
800
+ shutil.rmtree(chroma_dir)
801
+
802
+ if chats_db.exists():
803
+ chats_db.unlink()
804
+
805
+ if uploads_dir.exists():
806
+ for item in uploads_dir.iterdir():
807
+ if item.is_file():
808
+ item.unlink()
809
+ elif item.is_dir():
810
+ shutil.rmtree(item)
811
+
812
+ return {"ok": True, "message": "RAG data reset successful"}
813
+ except Exception as e:
814
+ raise HTTPException(status_code=500, detail=str(e))
815
+
816
  # ==============================
817
  # 16. SERVER STARTUP
818
  # ==============================