Spaces:
Sleeping
Sleeping
tcain commited on
Commit ·
f63fd03
1
Parent(s): ca4956f
Add
Browse filesrequest size limits
app.py
CHANGED
|
@@ -50,15 +50,27 @@ class ScrubResponse(BaseModel):
|
|
| 50 |
entities_found: int
|
| 51 |
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
@app.post("/scrub", response_model=ScrubResponse)
|
| 54 |
async def scrub(payload: ScrubRequest, x_api_key: str = Header(None)):
|
| 55 |
if API_KEY and x_api_key != API_KEY:
|
| 56 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
| 57 |
|
|
|
|
|
|
|
|
|
|
| 58 |
total_entities = 0
|
| 59 |
scrubbed_turns = []
|
| 60 |
|
| 61 |
for turn in payload.turns:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
text = turn.get("content", "")
|
| 63 |
role = turn.get("role", "")
|
| 64 |
|
|
|
|
| 50 |
entities_found: int
|
| 51 |
|
| 52 |
|
| 53 |
+
MAX_TURNS = 200
|
| 54 |
+
MAX_CONTENT_LENGTH = 100_000 # 100KB per turn
|
| 55 |
+
|
| 56 |
+
|
| 57 |
@app.post("/scrub", response_model=ScrubResponse)
|
| 58 |
async def scrub(payload: ScrubRequest, x_api_key: str = Header(None)):
|
| 59 |
if API_KEY and x_api_key != API_KEY:
|
| 60 |
raise HTTPException(status_code=401, detail="Invalid API key")
|
| 61 |
|
| 62 |
+
if len(payload.turns) > MAX_TURNS:
|
| 63 |
+
raise HTTPException(status_code=413, detail=f"Too many turns (max {MAX_TURNS})")
|
| 64 |
+
|
| 65 |
total_entities = 0
|
| 66 |
scrubbed_turns = []
|
| 67 |
|
| 68 |
for turn in payload.turns:
|
| 69 |
+
if len(turn.get("content", "")) > MAX_CONTENT_LENGTH:
|
| 70 |
+
raise HTTPException(
|
| 71 |
+
status_code=413,
|
| 72 |
+
detail=f"Turn content too large (max {MAX_CONTENT_LENGTH} bytes)",
|
| 73 |
+
)
|
| 74 |
text = turn.get("content", "")
|
| 75 |
role = turn.get("role", "")
|
| 76 |
|