Spaces:
Paused
Paused
feat: Add Request parameter to document upload and status endpoints for improved context handling
Browse files
app/__pycache__/main.cpython-39.pyc
CHANGED
|
Binary files a/app/__pycache__/main.cpython-39.pyc and b/app/__pycache__/main.cpython-39.pyc differ
|
|
|
app/__pycache__/rag.cpython-39.pyc
ADDED
|
Binary file (6.18 kB). View file
|
|
|
app/__pycache__/storage.cpython-39.pyc
CHANGED
|
Binary files a/app/__pycache__/storage.cpython-39.pyc and b/app/__pycache__/storage.cpython-39.pyc differ
|
|
|
app/main.py
CHANGED
|
@@ -2,7 +2,7 @@ import time
|
|
| 2 |
from pathlib import Path
|
| 3 |
from uuid import uuid4
|
| 4 |
|
| 5 |
-
from fastapi import FastAPI, UploadFile, File, BackgroundTasks, HTTPException
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from slowapi import Limiter
|
| 8 |
from slowapi.util import get_remote_address
|
|
@@ -35,7 +35,7 @@ def rate_limit_handler(request, exc):
|
|
| 35 |
|
| 36 |
@app.post("/documents/upload", response_model=UploadResponse)
|
| 37 |
@limiter.limit("10/minute")
|
| 38 |
-
async def upload_document(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
|
| 39 |
suffix = Path(file.filename).suffix.lower()
|
| 40 |
if suffix not in {".pdf", ".txt"}:
|
| 41 |
raise HTTPException(status_code=400, detail="Only PDF and TXT are supported")
|
|
@@ -63,7 +63,7 @@ async def upload_document(background_tasks: BackgroundTasks, file: UploadFile =
|
|
| 63 |
|
| 64 |
@app.get("/documents/status/{job_id}", response_model=JobStatus)
|
| 65 |
@limiter.limit("30/minute")
|
| 66 |
-
async def document_status(job_id: str):
|
| 67 |
job = get_job(job_id)
|
| 68 |
if not job:
|
| 69 |
raise HTTPException(status_code=404, detail="Job not found")
|
|
@@ -72,7 +72,7 @@ async def document_status(job_id: str):
|
|
| 72 |
|
| 73 |
@app.post("/qa", response_model=QAResponse)
|
| 74 |
@limiter.limit("30/minute")
|
| 75 |
-
async def ask_question(payload: QARequest):
|
| 76 |
started = time.time()
|
| 77 |
contexts = search(payload.question, payload.top_k or TOP_K_DEFAULT)
|
| 78 |
answer = generate_answer(payload.question, contexts)
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from uuid import uuid4
|
| 4 |
|
| 5 |
+
from fastapi import FastAPI, UploadFile, File, BackgroundTasks, HTTPException, Request
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from slowapi import Limiter
|
| 8 |
from slowapi.util import get_remote_address
|
|
|
|
| 35 |
|
| 36 |
@app.post("/documents/upload", response_model=UploadResponse)
|
| 37 |
@limiter.limit("10/minute")
|
| 38 |
+
async def upload_document(request: Request, background_tasks: BackgroundTasks, file: UploadFile = File(...)):
|
| 39 |
suffix = Path(file.filename).suffix.lower()
|
| 40 |
if suffix not in {".pdf", ".txt"}:
|
| 41 |
raise HTTPException(status_code=400, detail="Only PDF and TXT are supported")
|
|
|
|
| 63 |
|
| 64 |
@app.get("/documents/status/{job_id}", response_model=JobStatus)
|
| 65 |
@limiter.limit("30/minute")
|
| 66 |
+
async def document_status(request: Request, job_id: str):
|
| 67 |
job = get_job(job_id)
|
| 68 |
if not job:
|
| 69 |
raise HTTPException(status_code=404, detail="Job not found")
|
|
|
|
| 72 |
|
| 73 |
@app.post("/qa", response_model=QAResponse)
|
| 74 |
@limiter.limit("30/minute")
|
| 75 |
+
async def ask_question(request: Request, payload: QARequest):
|
| 76 |
started = time.time()
|
| 77 |
contexts = search(payload.question, payload.top_k or TOP_K_DEFAULT)
|
| 78 |
answer = generate_answer(payload.question, contexts)
|