Spaces:
Sleeping
Sleeping
File size: 987 Bytes
5551822 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import fastapi
import logging
import os
import shutil
from exception import MyException
from api.constants import DATA_FOLDER_PATH,DB_FOLDER_PATH
from src.MultiRag.graph.builder import deleteThread
router = fastapi.APIRouter()
@router.delete("/delete_thread")
async def delete_thread(thread_id: str):
try:
logging.info(f"Attempting to delete thread {thread_id}")
await deleteThread(thread_id)
data_path = f"{DATA_FOLDER_PATH}/{thread_id}"
db_path = f"{DB_FOLDER_PATH}/{thread_id}"
if os.path.exists(data_path):
shutil.rmtree(data_path)
if os.path.exists(db_path):
shutil.rmtree(db_path)
logging.info(f"Successfully deleted thread {thread_id}")
return {"message": f"Thread {thread_id} has been deleted."}
except Exception as e:
logging.error(f"Failed to delete thread {thread_id}: {str(e)}")
raise MyException("Failed to delete thread") from e |