Spaces:
Sleeping
Sleeping
Commit ·
cfa61a6
1
Parent(s): 5743bc2
fix: accept empty body on POST /reset (openenv checker compatibility)
Browse files- README.md +2 -2
- server/app.py +20 -3
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Guardian OpenEnv
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
|
@@ -9,7 +9,7 @@ tags:
|
|
| 9 |
- openenv
|
| 10 |
- compliance
|
| 11 |
- evaluation
|
| 12 |
-
short_description: OpenEnv benchmark for dark-pattern
|
| 13 |
---
|
| 14 |
|
| 15 |
# Guardian OpenEnv
|
|
|
|
| 1 |
---
|
| 2 |
title: Guardian OpenEnv
|
| 3 |
+
emoji: 🛡️
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
|
|
|
| 9 |
- openenv
|
| 10 |
- compliance
|
| 11 |
- evaluation
|
| 12 |
+
short_description: OpenEnv benchmark for checkout dark-pattern defense.
|
| 13 |
---
|
| 14 |
|
| 15 |
# Guardian OpenEnv
|
server/app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
from
|
|
|
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
|
| 6 |
from guardian_openenv.environment import GuardianReviewEnvironment
|
|
@@ -26,8 +28,22 @@ def health() -> dict:
|
|
| 26 |
|
| 27 |
|
| 28 |
@app.post("/reset", response_model=GuardianObservation)
|
| 29 |
-
def reset(
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
@app.post("/step", response_model=StepResult)
|
|
@@ -38,3 +54,4 @@ def step(action: GuardianAction) -> StepResult:
|
|
| 38 |
@app.get("/state", response_model=GuardianState)
|
| 39 |
def state() -> GuardianState:
|
| 40 |
return env.state()
|
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
from typing import Annotated
|
| 4 |
+
|
| 5 |
+
from fastapi import Body, FastAPI, Request
|
| 6 |
from pydantic import BaseModel
|
| 7 |
|
| 8 |
from guardian_openenv.environment import GuardianReviewEnvironment
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
@app.post("/reset", response_model=GuardianObservation)
|
| 31 |
+
async def reset(request: Request) -> GuardianObservation:
|
| 32 |
+
"""Accept POST /reset with an empty body OR a JSON body with optional task_id.
|
| 33 |
+
|
| 34 |
+
The OpenEnv automated checker sends an empty POST, which caused a 422 when
|
| 35 |
+
FastAPI required a JSON body. We now read the raw body and only parse it if
|
| 36 |
+
it contains non-empty content.
|
| 37 |
+
"""
|
| 38 |
+
task_id: str | None = None
|
| 39 |
+
try:
|
| 40 |
+
body = await request.body()
|
| 41 |
+
if body and body.strip() not in (b"", b"null"):
|
| 42 |
+
payload = ResetRequest.model_validate_json(body)
|
| 43 |
+
task_id = payload.task_id
|
| 44 |
+
except Exception: # noqa: BLE001
|
| 45 |
+
pass
|
| 46 |
+
return env.reset(task_id)
|
| 47 |
|
| 48 |
|
| 49 |
@app.post("/step", response_model=StepResult)
|
|
|
|
| 54 |
@app.get("/state", response_model=GuardianState)
|
| 55 |
def state() -> GuardianState:
|
| 56 |
return env.state()
|
| 57 |
+
|