Spaces:
Sleeping
Sleeping
from fastapi import APIRouter, File, HTTPException, UploadFile | |
from fastapi.responses import JSONResponse | |
from app.db_local_storage.vector_files_db import vector_files_db | |
from app.modules.uploadDocument.controllers.file_upload_controller import ( | |
FileUploadController, | |
) | |
from app.db_local_storage.documents_db import documents_db | |
router = APIRouter() | |
fileUploadController = FileUploadController() | |
async def get_all_documents(): | |
return JSONResponse(status_code=200, content={"data": documents_db}) | |
async def get_all_embeddings(): | |
return JSONResponse(status_code=200, content={"data": vector_files_db}) | |
async def delete_document(id: int): | |
document = next((doc for doc in documents_db if doc["id"] == id), None) | |
if document: | |
documents_db.remove(document) | |
else: | |
raise HTTPException(status_code=404, detail="Document not found") | |
vector_file_key = next( | |
( | |
key | |
for key, value in vector_files_db.items() | |
if value["metadata"]["id"] == id | |
), | |
None, | |
) | |
if vector_file_key: | |
del vector_files_db[vector_file_key] | |
return JSONResponse(status_code=200, content={"message": "Document deleted"}) | |
# { | |
# "data": { | |
# "document_1": { | |
# "metadata": { | |
# "id": 1, | |
# "filename": "doc_test.pdf", | |
# "chunks": 4 | |
# }, | |
async def upload_file(file: UploadFile = File(...)): | |
return await fileUploadController.handle_file_upload(file) | |