Spaces:
Running
Running
Update app/api/routes.py
Browse files- app/api/routes.py +2 -49
app/api/routes.py
CHANGED
|
@@ -122,42 +122,6 @@ 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:
|
| 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:
|
|
@@ -193,7 +157,6 @@ async def delete_chat(chat_id: str):
|
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
-
|
| 197 |
# ---------------------------------------------------
|
| 198 |
# ✅ Chat Query Endpoint (Persistent Memory)
|
| 199 |
# ---------------------------------------------------
|
|
@@ -216,16 +179,7 @@ async def query_pdf(doc_id: str = Form(...), question: str = Form(...)):
|
|
| 216 |
|
| 217 |
# ✅ Vector Search
|
| 218 |
question_vector = embedder.encode([question])[0].tolist()
|
| 219 |
-
|
| 220 |
-
# collection_name=COLLECTION_NAME,
|
| 221 |
-
# query_vector=question_vector,
|
| 222 |
-
# query_filter=Filter(
|
| 223 |
-
# must=[FieldCondition(key="doc_id", match=MatchValue(value=doc_id))]
|
| 224 |
-
# ),
|
| 225 |
-
# limit=5,
|
| 226 |
-
# )
|
| 227 |
-
|
| 228 |
-
|
| 229 |
hits = qdrant_client.query_points(
|
| 230 |
collection_name=COLLECTION_NAME,
|
| 231 |
query=question_vector,
|
|
@@ -262,5 +216,4 @@ async def get_conversation(doc_id: str):
|
|
| 262 |
doc = conversations.find_one({"doc_id": doc_id})
|
| 263 |
if not doc:
|
| 264 |
return {"history": []}
|
| 265 |
-
return {"history": doc.get("history", [])}
|
| 266 |
-
|
|
|
|
| 122 |
# ---------------------------------------------------
|
| 123 |
# ✅ Delete Chat (Qdrant + Mongo + File)
|
| 124 |
# ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
@router.delete("/chat/{chat_id}")
|
| 126 |
async def delete_chat(chat_id: str):
|
| 127 |
try:
|
|
|
|
| 157 |
|
| 158 |
|
| 159 |
|
|
|
|
| 160 |
# ---------------------------------------------------
|
| 161 |
# ✅ Chat Query Endpoint (Persistent Memory)
|
| 162 |
# ---------------------------------------------------
|
|
|
|
| 179 |
|
| 180 |
# ✅ Vector Search
|
| 181 |
question_vector = embedder.encode([question])[0].tolist()
|
| 182 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
hits = qdrant_client.query_points(
|
| 184 |
collection_name=COLLECTION_NAME,
|
| 185 |
query=question_vector,
|
|
|
|
| 216 |
doc = conversations.find_one({"doc_id": doc_id})
|
| 217 |
if not doc:
|
| 218 |
return {"history": []}
|
| 219 |
+
return {"history": doc.get("history", [])}
|
|
|