Spaces:
Runtime error
Runtime error
Download app/api/metadata.py from diptaraj/rag-pipeline-api: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/spaces/diptaraj/rag-pipeline-api/resolve/main/app/api/metadata.py
- Command line
-
hf download hf://spaces/diptaraj/rag-pipeline-api/app/api/metadata.py
-
curl -L -o metadata.py https://huggingface.co/spaces/diptaraj/rag-pipeline-api/resolve/main/app/api/metadata.py
1.83 kB
| from fastapi import APIRouter, HTTPException | |
| from ..services.doc_store import list_documents, delete_document, get_document_stats | |
| router = APIRouter(prefix="/metadata", tags=["Document Metadata"]) | |
| async def get_all_metadata(): | |
| """Get metadata for all uploaded documents""" | |
| try: | |
| documents = list_documents() | |
| stats = get_document_stats() | |
| return { | |
| "documents": documents, | |
| "stats": stats | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Failed to retrieve metadata: {str(e)}") | |
| async def get_metadata_stats(): | |
| """Get document statistics""" | |
| try: | |
| return get_document_stats() | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Failed to retrieve stats: {str(e)}") | |
| async def delete_document_metadata(doc_id: str): | |
| """Delete document metadata (note: does not remove from vector store)""" | |
| try: | |
| success = delete_document(doc_id) | |
| if success: | |
| return {"message": f"Document {doc_id} metadata deleted successfully"} | |
| else: | |
| raise HTTPException(status_code=404, detail="Document not found") | |
| except HTTPException: | |
| raise | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Failed to delete document: {str(e)}") | |
| async def metadata_health(): | |
| """Health check for metadata service""" | |
| try: | |
| stats = get_document_stats() | |
| return { | |
| "status": "healthy", | |
| "database": "connected", | |
| "stats": stats | |
| } | |
| except Exception as e: | |
| return { | |
| "status": "unhealthy", | |
| "database": "error", | |
| "error": str(e) | |
| } | |