Spaces:
Sleeping
Sleeping
Download api/routes/documents.py from Qurrah/replyflow-rag: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/api/routes/documents.py
- Command line
-
hf download hf://spaces/Qurrah/replyflow-rag/api/routes/documents.py
-
curl -L -o documents.py https://huggingface.co/spaces/Qurrah/replyflow-rag/resolve/main/api/routes/documents.py
1.58 kB
| import logging | |
| from fastapi import APIRouter, BackgroundTasks, Security | |
| from api.schemas import IngestDocumentRequest | |
| from core.security import verify_api_key | |
| from services.document_service import ( | |
| delete_document as delete_document_service, | |
| ensure_workspace_exists, | |
| get_document_status, | |
| queue_document_ingest, | |
| validate_supported_mime, | |
| ) | |
| logger = logging.getLogger(__name__) | |
| router = APIRouter(tags=["documents"]) | |
| async def ingest_document( | |
| req: IngestDocumentRequest, | |
| background_tasks: BackgroundTasks, | |
| _: str = Security(verify_api_key), | |
| ): | |
| validate_supported_mime(req.mime) # → 400 via ValueError handler | |
| ensure_workspace_exists(req.workspace_slug) # → 404 via WorkspaceNotFoundError handler | |
| queue_document_ingest( | |
| background_tasks, | |
| workspace_slug=req.workspace_slug, | |
| document_id=req.document_id, | |
| source_url=req.source_url, | |
| mime=req.mime, | |
| title=req.title, | |
| ) | |
| return {"status": "queued"} | |
| async def document_status( | |
| document_id: str, | |
| workspace_slug: str, | |
| _: str = Security(verify_api_key), | |
| ): | |
| return get_document_status(document_id, workspace_slug) | |
| async def delete_document( | |
| document_id: str, | |
| workspace_slug: str, | |
| _: str = Security(verify_api_key), | |
| ): | |
| delete_document_service(document_id, workspace_slug) | |
| return {"status": "ok", "message": f"Document '{document_id}' deleted"} | |