Spaces:
Sleeping
Sleeping
Commit ·
47da4c9
1
Parent(s): d6ece09
Fix: support optional task_id/task field and action_type
Browse files
app.py
CHANGED
|
@@ -22,84 +22,26 @@ _http_env: Optional[MLOpsEnvironment] = None
|
|
| 22 |
|
| 23 |
|
| 24 |
class ResetRequest(BaseModel):
|
| 25 |
-
task_id: str = "easy"
|
| 26 |
seed: Optional[int] = None
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
class StepResponse(BaseModel):
|
| 30 |
-
observation: MLOpsObservation
|
| 31 |
-
reward: float
|
| 32 |
-
done: bool
|
| 33 |
-
info: Dict[str, Any]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
@app.get("/")
|
| 37 |
-
async def root():
|
| 38 |
-
return {
|
| 39 |
-
"message": "MLOps Pipeline Debugger API",
|
| 40 |
-
"version": "1.0.0",
|
| 41 |
-
"docs": "This is an OpenEnv-compatible RL environment",
|
| 42 |
-
"endpoints": {
|
| 43 |
-
"GET /": "This message",
|
| 44 |
-
"GET /health": "Health check",
|
| 45 |
-
"GET /tasks": "List available tasks",
|
| 46 |
-
"GET /openenv/state": "OpenEnv state",
|
| 47 |
-
"POST /reset": "Start a new episode",
|
| 48 |
-
"POST /step": "Take an action",
|
| 49 |
-
"GET /state": "Get current state",
|
| 50 |
-
},
|
| 51 |
-
"space_url": "https://angelgupta-mlops-openenv.hf.space",
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
@app.get("/health")
|
| 56 |
-
async def health():
|
| 57 |
-
return {"status": "ok", "environment": "mlops_debug_env", "version": "1.0.0"}
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
@app.get("/openenv/state", response_model=OpenEnvState)
|
| 61 |
-
def openenv_state():
|
| 62 |
-
# Expose the current OpenEnv-like state persisted in memory/state.json
|
| 63 |
-
return OPENENV_STATE
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
@app.get("/tasks")
|
| 67 |
-
async def list_tasks():
|
| 68 |
-
return {
|
| 69 |
-
"tasks": [
|
| 70 |
-
{
|
| 71 |
-
"task_id": "easy",
|
| 72 |
-
"name": "Config Error Diagnosis",
|
| 73 |
-
"difficulty": "easy",
|
| 74 |
-
"max_steps": 20,
|
| 75 |
-
},
|
| 76 |
-
{
|
| 77 |
-
"task_id": "medium",
|
| 78 |
-
"name": "Data Leakage Detection",
|
| 79 |
-
"difficulty": "medium",
|
| 80 |
-
"max_steps": 30,
|
| 81 |
-
},
|
| 82 |
-
{
|
| 83 |
-
"task_id": "hard",
|
| 84 |
-
"name": "Silent Evaluation Bug",
|
| 85 |
-
"difficulty": "hard",
|
| 86 |
-
"max_steps": 40,
|
| 87 |
-
},
|
| 88 |
-
]
|
| 89 |
-
}
|
| 90 |
|
| 91 |
|
| 92 |
@app.post("/reset", response_model=MLOpsObservation)
|
| 93 |
async def reset(req: ResetRequest):
|
| 94 |
global _http_env
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
return _http_env.reset(seed=req.seed)
|
| 97 |
|
| 98 |
|
| 99 |
@app.post("/step", response_model=StepResponse)
|
| 100 |
-
async def step(action: MLOpsAction):
|
| 101 |
if _http_env is None:
|
| 102 |
raise HTTPException(400, "Call /reset first.")
|
|
|
|
|
|
|
| 103 |
obs, reward, done, info = _http_env.step(action)
|
| 104 |
return StepResponse(observation=obs, reward=reward, done=done, info=info)
|
| 105 |
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
class ResetRequest(BaseModel):
|
| 25 |
+
task_id: Optional[str] = "easy"
|
| 26 |
seed: Optional[int] = None
|
| 27 |
+
task: Optional[str] = None # Support both task_id and task
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
@app.post("/reset", response_model=MLOpsObservation)
|
| 31 |
async def reset(req: ResetRequest):
|
| 32 |
global _http_env
|
| 33 |
+
# Support both field names for compatibility
|
| 34 |
+
task_id = req.task_id or req.task or "easy"
|
| 35 |
+
_http_env = MLOpsEnvironment(task_id=task_id)
|
| 36 |
return _http_env.reset(seed=req.seed)
|
| 37 |
|
| 38 |
|
| 39 |
@app.post("/step", response_model=StepResponse)
|
| 40 |
+
async def step(action: Optional[MLOpsAction] = None):
|
| 41 |
if _http_env is None:
|
| 42 |
raise HTTPException(400, "Call /reset first.")
|
| 43 |
+
if action is None or action.action_type is None:
|
| 44 |
+
raise HTTPException(422, "Field required: action_type")
|
| 45 |
obs, reward, done, info = _http_env.step(action)
|
| 46 |
return StepResponse(observation=obs, reward=reward, done=done, info=info)
|
| 47 |
|