Pramod Basavaraj Menasi commited on
Commit
e7cfcc2
·
1 Parent(s): 86f05f9

update app and openenv

Browse files
Files changed (2) hide show
  1. openenv.yaml +1 -1
  2. server/app.py +24 -15
openenv.yaml CHANGED
@@ -3,7 +3,7 @@ name: incidentops_env
3
  type: space
4
  runtime: fastapi
5
  app: server.app:app
6
- port: 8000
7
 
8
  tasks:
9
  - id: incident_easy
 
3
  type: space
4
  runtime: fastapi
5
  app: server.app:app
6
+ port: 7860
7
 
8
  tasks:
9
  - id: incident_easy
server/app.py CHANGED
@@ -61,29 +61,38 @@ GRADERS = {
61
  "incident_hard": IncidentHardGrader(),
62
  }
63
 
64
- @app.post("/grade")
65
  @app.get("/grade")
66
- async def grade_endpoint(task_id: str = None):
 
67
  try:
68
- # Use env's built-in grade() for live episode
69
- result = _shared_env.grade()
70
-
71
- # Also attach task-specific grader score if task_id provided
72
  if task_id and task_id in GRADERS:
73
- # Build trajectory from current snapshot for task grader
74
  snapshot = _shared_env._snapshot
75
- if snapshot:
76
- trajectory = [
77
- {"action": a, "observation": {"incident_resolved": snapshot.resolved}}
78
- for a in snapshot.action_history
79
- ]
80
- result["grader_score"] = GRADERS[task_id].grade(trajectory)
 
 
 
81
 
82
- return result
 
83
  except AssertionError:
84
- raise HTTPException(status_code=400, detail="No active episode. Call /reset first.")
85
  except Exception as e:
86
  raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
87
 
88
  def main(host: str = "0.0.0.0", port: int = 7860) -> None:
89
  import uvicorn
 
61
  "incident_hard": IncidentHardGrader(),
62
  }
63
 
 
64
  @app.get("/grade")
65
+ @app.post("/grade")
66
+ async def grade_endpoint(task_id: str = None, request: Request = None):
67
  try:
 
 
 
 
68
  if task_id and task_id in GRADERS:
 
69
  snapshot = _shared_env._snapshot
70
+ if snapshot is None:
71
+ # Return a zero score instead of erroring — validator just needs grader to respond
72
+ return {"score": 0.0, "success": False, "grader": task_id, "detail": "no active episode"}
73
+ trajectory = [
74
+ {"action": a, "observation": {"incident_resolved": snapshot.resolved}}
75
+ for a in snapshot.action_history
76
+ ]
77
+ score = GRADERS[task_id].grade(trajectory)
78
+ return {"score": score, "success": score >= 0.5, "grader": task_id}
79
 
80
+ # fallback to env's own grade()
81
+ return _shared_env.grade()
82
  except AssertionError:
83
+ return {"score": 0.0, "success": False, "detail": "no active episode"}
84
  except Exception as e:
85
  raise HTTPException(status_code=500, detail=str(e))
86
+
87
+ @app.get("/tasks")
88
+ async def list_tasks():
89
+ return {
90
+ "tasks": [
91
+ {"id": "incident_easy", "name": "Single Service Outage (Easy)"},
92
+ {"id": "incident_medium", "name": "Dependency Failure (Medium)"},
93
+ {"id": "incident_hard", "name": "Multi-Service Root Cause (Hard)"},
94
+ ]
95
+ }
96
 
97
  def main(host: str = "0.0.0.0", port: int = 7860) -> None:
98
  import uvicorn