Spaces:
Running
Running
Update app/api/routes.py
Browse files- app/api/routes.py +37 -0
app/api/routes.py
CHANGED
|
@@ -122,6 +122,42 @@ async def get_all_chats():
|
|
| 122 |
# ---------------------------------------------------
|
| 123 |
# ✅ Delete Chat (Qdrant + Mongo + File)
|
| 124 |
# ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
@router.delete("/chat/{chat_id}")
|
| 126 |
async def delete_chat(chat_id: str):
|
| 127 |
try:
|
|
@@ -227,3 +263,4 @@ async def get_conversation(doc_id: str):
|
|
| 227 |
if not doc:
|
| 228 |
return {"history": []}
|
| 229 |
return {"history": doc.get("history", [])}
|
|
|
|
|
|
| 122 |
# ---------------------------------------------------
|
| 123 |
# ✅ Delete Chat (Qdrant + Mongo + File)
|
| 124 |
# ---------------------------------------------------
|
| 125 |
+
# @router.delete("/chat/{chat_id}")
|
| 126 |
+
# async def delete_chat(chat_id: str):
|
| 127 |
+
# try:
|
| 128 |
+
# chat = conversations.find_one({"_id": ObjectId(chat_id)})
|
| 129 |
+
# if not chat:
|
| 130 |
+
# raise HTTPException(status_code=404, detail="Chat not found")
|
| 131 |
+
|
| 132 |
+
# doc_id = chat.get("doc_id")
|
| 133 |
+
# qdrant_collection = chat.get("qdrant_collection")
|
| 134 |
+
|
| 135 |
+
# # ✅ Delete embeddings from Qdrant
|
| 136 |
+
# try:
|
| 137 |
+
# qdrant_client.delete(
|
| 138 |
+
# collection_name=qdrant_collection,
|
| 139 |
+
# points_selector=Filter(
|
| 140 |
+
# must=[FieldCondition(key="doc_id", match=MatchValue(value=doc_id))]
|
| 141 |
+
# ),
|
| 142 |
+
# )
|
| 143 |
+
# except Exception as e:
|
| 144 |
+
# print(f"⚠️ Qdrant delete failed: {e}")
|
| 145 |
+
|
| 146 |
+
# # ✅ Delete uploaded file
|
| 147 |
+
# file_path = chat.get("file_path")
|
| 148 |
+
# if file_path and os.path.exists(file_path):
|
| 149 |
+
# os.remove(file_path)
|
| 150 |
+
|
| 151 |
+
# # ✅ Delete from MongoDB
|
| 152 |
+
# conversations.delete_one({"_id": ObjectId(chat_id)})
|
| 153 |
+
|
| 154 |
+
# return {"status": "success", "message": "Chat deleted successfully"}
|
| 155 |
+
|
| 156 |
+
# except Exception as e:
|
| 157 |
+
# raise HTTPException(status_code=500, detail=str(e))
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
|
| 161 |
@router.delete("/chat/{chat_id}")
|
| 162 |
async def delete_chat(chat_id: str):
|
| 163 |
try:
|
|
|
|
| 263 |
if not doc:
|
| 264 |
return {"history": []}
|
| 265 |
return {"history": doc.get("history", [])}
|
| 266 |
+
|