"""FastAPI server for ForgeEnv (OpenEnv-compliant). Exposes /reset, /step, /state HTTP endpoints via OpenEnv's `create_app`. HF Spaces sets PORT=7860 automatically. """ from __future__ import annotations import os from fastapi.responses import HTMLResponse from openenv.core import create_app from forgeenv.env.actions import ForgeAction from forgeenv.env.forge_environment import ForgeEnvironment from forgeenv.env.observations import ForgeObservation app = create_app( env=ForgeEnvironment, action_cls=ForgeAction, observation_cls=ForgeObservation, env_name="forgeenv", ) _LANDING_HTML = """
OpenEnv-compliant RL environment for HuggingFace ecosystem repair under library version drift.
This URL serves the environment over HTTP. It is not a UI — it's the runtime that training notebooks connect to. Open one of the endpoints below, or use the demo Space to try the trained Repair Agent in a browser.
| Method | Path | Purpose |
|---|---|---|
| GET | /health | Health probe |
| POST | /reset | Sample task, return drift-gen observation |
| POST | /step | Apply ForgeAction (breakage or repair) |
| GET | /state | Current internal state |
| GET | /metadata | Env name + version + schema URLs |
| GET | /schema | Action / observation JSON schemas |
| GET | /docs | Interactive Swagger UI |
import asyncio
from openenv.core import GenericEnvClient
async def go():
client = GenericEnvClient(base_url="https://akhiilll-forgeenv.hf.space")
obs = await client.reset()
print(obs.observation["current_phase"], obs.observation["task_id"])
asyncio.run(go())
Tip: if links don't open from inside the embedded Space frame, right-click and choose Open in new tab, or open this URL directly at akhiilll-forgeenv.hf.space.
""" def _attach_supplementary_routes(_app) -> None: """Add /health and a friendly GET / landing page if not present.""" existing = { getattr(r, "path", None) for r in getattr(_app, "routes", []) } if "/health" not in existing: @_app.get("/health") def _health() -> dict: return {"status": "ok", "env": "forgeenv"} if "/" not in existing: @_app.get("/", response_class=HTMLResponse, include_in_schema=False) def _root() -> str: return _LANDING_HTML _attach_supplementary_routes(app) if __name__ == "__main__": import uvicorn port = int(os.environ.get("PORT", "7860")) uvicorn.run(app, host="0.0.0.0", port=port)