Spaces:
Sleeping
Sleeping
| """ | |
| server/app.py — primary FastAPI entry point expected by the OpenEnv validator. | |
| This module re-exports the FastAPI app from grid_env.Server.app so the | |
| validator's 'server/app.py' requirement is satisfied while keeping all | |
| environment logic in grid_env/. | |
| """ | |
| from __future__ import annotations | |
| import uvicorn | |
| from typing import Optional | |
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel, Field | |
| from grid_env.Server.warehouse_env import WarehouseEnvService | |
| app = FastAPI( | |
| title="Warehouse Fulfillment Env Server", | |
| version="0.1.0", | |
| description="HTTP server for the MiniGrid-style warehouse fulfillment environment.", | |
| ) | |
| service = WarehouseEnvService() | |
| class ResetRequest(BaseModel): | |
| task_id: Optional[str] = Field(default=None, description="Task ID to load on reset.") | |
| seed: Optional[int] = Field(default=None, description="Optional deterministic seed.") | |
| class StepRequest(BaseModel): | |
| command: str = Field(description="Environment action command.") | |
| def health() -> dict: | |
| return service.health() | |
| def tasks() -> dict: | |
| return service.tasks() | |
| def reset(payload: ResetRequest = None) -> dict: | |
| task_id = payload.task_id if payload else None | |
| seed = payload.seed if payload else None | |
| try: | |
| return service.reset(task_id=task_id, seed=seed) | |
| except KeyError as exc: | |
| raise HTTPException(status_code=404, detail=str(exc)) from exc | |
| def step(payload: StepRequest) -> dict: | |
| try: | |
| return service.step(command=payload.command) | |
| except ValueError as exc: | |
| raise HTTPException(status_code=400, detail=str(exc)) from exc | |
| def state() -> dict: | |
| return service.state() | |
| def main() -> None: | |
| uvicorn.run("server.app:app", host="0.0.0.0", port=8000, reload=False) | |
| if __name__ == "__main__": | |
| main() | |