Spaces:
Sleeping
Sleeping
Commit ·
3763d6d
1
Parent(s): 47da4c9
Fix: support multiple action formats
Browse files
app.py
CHANGED
|
@@ -37,11 +37,23 @@ async def reset(req: ResetRequest):
|
|
| 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 |
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
@app.post("/step", response_model=StepResponse)
|
| 40 |
+
async def step(action: Optional[MLOpsAction] = None, data: Optional[dict] = None):
|
| 41 |
if _http_env is None:
|
| 42 |
raise HTTPException(400, "Call /reset first.")
|
| 43 |
+
|
| 44 |
+
# Handle various input formats
|
| 45 |
+
if action is None and data is not None:
|
| 46 |
+
# Try different formats
|
| 47 |
+
if "action_type" in data:
|
| 48 |
+
action = MLOpsAction(**data)
|
| 49 |
+
elif "action" in data:
|
| 50 |
+
action = MLOpsAction(**data["action"])
|
| 51 |
+
elif "message" in data:
|
| 52 |
+
action = MLOpsAction(action_type=data["message"])
|
| 53 |
+
|
| 54 |
if action is None or action.action_type is None:
|
| 55 |
raise HTTPException(422, "Field required: action_type")
|
| 56 |
+
|
| 57 |
obs, reward, done, info = _http_env.step(action)
|
| 58 |
return StepResponse(observation=obs, reward=reward, done=done, info=info)
|
| 59 |
|