Spaces:
Sleeping
Sleeping
Commit ·
202f5d9
1
Parent(s): 0e662d7
feat(app): add POST /step endpoint — executes one attack turn, returns StepResult
Browse files- server/app.py +11 -1
server/app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from contextlib import asynccontextmanager
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from models import ResetResponse
|
| 5 |
from server.environment import RedTeamEnvironment
|
| 6 |
from server.config import get_settings
|
| 7 |
|
|
@@ -46,3 +46,13 @@ async def reset_episode():
|
|
| 46 |
return ResetResponse(observation=observation, episode_id=observation.episode_id)
|
| 47 |
except Exception as e:
|
| 48 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from contextlib import asynccontextmanager
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from models import AttackAction, StepResult, ResetResponse
|
| 5 |
from server.environment import RedTeamEnvironment
|
| 6 |
from server.config import get_settings
|
| 7 |
|
|
|
|
| 46 |
return ResetResponse(observation=observation, episode_id=observation.episode_id)
|
| 47 |
except Exception as e:
|
| 48 |
raise HTTPException(status_code=500, detail=str(e))
|
| 49 |
+
|
| 50 |
+
@app.post("/step", response_model=StepResult)
|
| 51 |
+
async def step_episode(action: AttackAction):
|
| 52 |
+
try:
|
| 53 |
+
result = await env.step(action)
|
| 54 |
+
return result
|
| 55 |
+
except ValueError as e:
|
| 56 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 57 |
+
except Exception as e:
|
| 58 |
+
raise HTTPException(status_code=500, detail=str(e))
|