Download server/api.py from Veer15/openenv-distributed-systems-debugging: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/Veer15/openenv-distributed-systems-debugging/resolve/main/server/api.py
- Command line
-
hf download hf://spaces/Veer15/openenv-distributed-systems-debugging/server/api.py
-
curl -L -o api.py https://huggingface.co/spaces/Veer15/openenv-distributed-systems-debugging/resolve/main/server/api.py
1.8 kB
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI, HTTPException | |
| from .constants import TaskName | |
| from .env import DistributedDebugEnv | |
| from .models import Action, Observation, StepResult | |
| async def lifespan(app: FastAPI): | |
| env = DistributedDebugEnv() | |
| env.start() | |
| app.state.env = env | |
| try: | |
| yield | |
| finally: | |
| env.close() | |
| app = FastAPI(title="Distributed Systems Debug Environment", version="1.0.0", lifespan=lifespan) | |
| async def reset(task_name: str | None = None) -> Observation: | |
| # Validator and sample inference call /reset without task input. | |
| # Use a deterministic default task for reproducible episode bootstrapping. | |
| selected_task_name = task_name or TaskName.CASCADING_TIMEOUT.value | |
| try: | |
| task = TaskName.parse(selected_task_name) | |
| except ValueError as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) from exc | |
| try: | |
| env: DistributedDebugEnv = app.state.env | |
| return env.reset(task_name=task) | |
| except Exception as exc: | |
| raise HTTPException(status_code=500, detail=str(exc)) from exc | |
| async def step(action: Action) -> StepResult: | |
| try: | |
| env: DistributedDebugEnv = app.state.env | |
| return env.step(action) | |
| except Exception as exc: | |
| raise HTTPException(status_code=500, detail=str(exc)) from exc | |
| async def state() -> dict: | |
| try: | |
| env: DistributedDebugEnv = app.state.env | |
| return env.state() | |
| except Exception as exc: | |
| raise HTTPException(status_code=500, detail=str(exc)) from exc | |
| async def health() -> dict: | |
| return {"status": "ok", "version": "1.0.0"} | |