soonvalley04 commited on
Commit
8f31158
Β·
verified Β·
1 Parent(s): f74ce35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -67,7 +67,7 @@ def get_or_create_env(agent_id: str):
67
 
68
 
69
  # ── FastAPI App ───────────────────────────────────────────────────────────────
70
- fastapi_app = FastAPI(
71
  title="OpenEnv: Split-Brain Collapse",
72
  description=(
73
  "An OpenEnv-compliant multi-agent RL environment simulating a "
@@ -83,7 +83,7 @@ fastapi_app = FastAPI(
83
  # CORE RL API (openenv validate + external agents)
84
  # ══════════════════════════════════════════════════════════════════════════════
85
 
86
- @fastapi_app.get("/health")
87
  def health():
88
  """Health check β€” returns 200 OK."""
89
  return {
@@ -95,7 +95,7 @@ def health():
95
  }
96
 
97
 
98
- @fastapi_app.post("/reset")
99
  async def reset(request: Request):
100
  """
101
  Reset the environment for a given task.
@@ -120,7 +120,7 @@ async def reset(request: Request):
120
  return JSONResponse(content=obs.model_dump())
121
 
122
 
123
- @fastapi_app.post("/step")
124
  async def step(request: Request):
125
  """Execute one raw action in the environment."""
126
  if active_env is None:
@@ -131,7 +131,7 @@ async def step(request: Request):
131
  return JSONResponse(content=result.model_dump())
132
 
133
 
134
- @fastapi_app.get("/state")
135
  def state():
136
  """Return the current observation without advancing the episode."""
137
  if active_env is None:
@@ -139,7 +139,7 @@ def state():
139
  return JSONResponse(content=active_env.state().model_dump())
140
 
141
 
142
- @fastapi_app.get("/tasks")
143
  def list_tasks(agent_id: str = "split_brain"):
144
  """List all available tasks with difficulty metadata for a specific agent."""
145
  if agent_id not in AGENT_REGISTRY:
@@ -151,7 +151,7 @@ def list_tasks(agent_id: str = "split_brain"):
151
  # AGENT REGISTRY API (frontend discovers agents + tasks)
152
  # ══════════════════════════════════════════════════════════════════════════════
153
 
154
- @fastapi_app.get("/agents")
155
  def list_agents():
156
  """
157
  Return all registered agents with their tasks.
@@ -179,7 +179,7 @@ class AgentStepRequest(BaseModel):
179
  task: Optional[str] = Field(None, description="Task hint (set via /reset)")
180
 
181
 
182
- @fastapi_app.post("/agent/step")
183
  def agent_step(body: AgentStepRequest):
184
  """
185
  Run ONE LLM-powered step on the active Split-Brain environment.
@@ -242,9 +242,9 @@ def agent_step(body: AgentStepRequest):
242
  # STATIC FILES β€” serves static/index.html at /
243
  # Mount AFTER all API routes so API routes take priority.
244
  # ══════════════════════════════════════════════════════════════════════════════
245
- fastapi_app.mount("/", StaticFiles(directory="static", html=True), name="static")
246
 
247
 
248
  if __name__ == "__main__":
249
  # Change "app:app" (implicit) to "app:fastapi_app"
250
- uvicorn.run("app:fastapi_app", host="0.0.0.0", port=7860, log_level="info")
 
67
 
68
 
69
  # ── FastAPI App ───────────────────────────────────────────────────────────────
70
+ app = FastAPI(
71
  title="OpenEnv: Split-Brain Collapse",
72
  description=(
73
  "An OpenEnv-compliant multi-agent RL environment simulating a "
 
83
  # CORE RL API (openenv validate + external agents)
84
  # ══════════════════════════════════════════════════════════════════════════════
85
 
86
+ @app.get("/health")
87
  def health():
88
  """Health check β€” returns 200 OK."""
89
  return {
 
95
  }
96
 
97
 
98
+ @app.post("/reset")
99
  async def reset(request: Request):
100
  """
101
  Reset the environment for a given task.
 
120
  return JSONResponse(content=obs.model_dump())
121
 
122
 
123
+ @app.post("/step")
124
  async def step(request: Request):
125
  """Execute one raw action in the environment."""
126
  if active_env is None:
 
131
  return JSONResponse(content=result.model_dump())
132
 
133
 
134
+ @app.get("/state")
135
  def state():
136
  """Return the current observation without advancing the episode."""
137
  if active_env is None:
 
139
  return JSONResponse(content=active_env.state().model_dump())
140
 
141
 
142
+ @app.get("/tasks")
143
  def list_tasks(agent_id: str = "split_brain"):
144
  """List all available tasks with difficulty metadata for a specific agent."""
145
  if agent_id not in AGENT_REGISTRY:
 
151
  # AGENT REGISTRY API (frontend discovers agents + tasks)
152
  # ══════════════════════════════════════════════════════════════════════════════
153
 
154
+ @app.get("/agents")
155
  def list_agents():
156
  """
157
  Return all registered agents with their tasks.
 
179
  task: Optional[str] = Field(None, description="Task hint (set via /reset)")
180
 
181
 
182
+ @app.post("/agent/step")
183
  def agent_step(body: AgentStepRequest):
184
  """
185
  Run ONE LLM-powered step on the active Split-Brain environment.
 
242
  # STATIC FILES β€” serves static/index.html at /
243
  # Mount AFTER all API routes so API routes take priority.
244
  # ══════════════════════════════════════════════════════════════════════════════
245
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
246
 
247
 
248
  if __name__ == "__main__":
249
  # Change "app:app" (implicit) to "app:fastapi_app"
250
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")