Spaces:
Runtime error
Runtime error
prashasti commited on
Commit ·
5d68774
1
Parent(s): 01468da
Changes for app.py
Browse files
app.py
CHANGED
|
@@ -12,10 +12,8 @@ from typing import Dict, Any, Optional
|
|
| 12 |
|
| 13 |
import os
|
| 14 |
import uvicorn
|
| 15 |
-
from fastapi import FastAPI, HTTPException
|
| 16 |
-
from pydantic import BaseModel
|
| 17 |
|
| 18 |
-
# Import your environments
|
| 19 |
from tasks.task_simple import create_env as create_simple
|
| 20 |
from tasks.task_multi_service import create_env as create_multi
|
| 21 |
from tasks.task_critical import create_env as create_critical
|
|
@@ -23,15 +21,8 @@ from tasks.task_critical import create_env as create_critical
|
|
| 23 |
|
| 24 |
app = FastAPI(title="DebugOps AI Environment", version="1.0.0")
|
| 25 |
|
| 26 |
-
# Global
|
| 27 |
-
_env = None
|
| 28 |
-
|
| 29 |
-
class ResetRequest(BaseModel):
|
| 30 |
-
task: str = "simple" # simple | multi_service | critical
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
class StepRequest(BaseModel):
|
| 34 |
-
action: str
|
| 35 |
|
| 36 |
def create_env(task: str):
|
| 37 |
if task == "simple":
|
|
@@ -65,10 +56,19 @@ def health():
|
|
| 65 |
|
| 66 |
|
| 67 |
@app.post("/reset")
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
global _env
|
|
|
|
| 70 |
try:
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
obs = _env.reset()
|
| 73 |
|
| 74 |
return {
|
|
@@ -81,11 +81,16 @@ def reset(request: ResetRequest):
|
|
| 81 |
|
| 82 |
|
| 83 |
@app.post("/step")
|
| 84 |
-
|
|
|
|
| 85 |
env = get_env()
|
| 86 |
|
| 87 |
try:
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
return {
|
| 91 |
"observation": obs,
|
|
@@ -99,6 +104,7 @@ def step(request: StepRequest):
|
|
| 99 |
|
| 100 |
|
| 101 |
@app.get("/state")
|
|
|
|
| 102 |
def state():
|
| 103 |
env = get_env()
|
| 104 |
try:
|
|
|
|
| 12 |
|
| 13 |
import os
|
| 14 |
import uvicorn
|
| 15 |
+
from fastapi import FastAPI, HTTPException, Body
|
|
|
|
| 16 |
|
|
|
|
| 17 |
from tasks.task_simple import create_env as create_simple
|
| 18 |
from tasks.task_multi_service import create_env as create_multi
|
| 19 |
from tasks.task_critical import create_env as create_critical
|
|
|
|
| 21 |
|
| 22 |
app = FastAPI(title="DebugOps AI Environment", version="1.0.0")
|
| 23 |
|
| 24 |
+
# Global environment instance
|
| 25 |
+
_env: Optional[Any] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def create_env(task: str):
|
| 28 |
if task == "simple":
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
@app.post("/reset")
|
| 59 |
+
@app.post("/reset/")
|
| 60 |
+
def reset(payload: Optional[Dict[str, Any]] = Body(default={})):
|
| 61 |
+
"""
|
| 62 |
+
Accepts BOTH:
|
| 63 |
+
{} (validator case)
|
| 64 |
+
{"task": "critical"} (manual case)
|
| 65 |
+
"""
|
| 66 |
global _env
|
| 67 |
+
|
| 68 |
try:
|
| 69 |
+
task = payload.get("task", "simple") if payload else "simple"
|
| 70 |
+
|
| 71 |
+
_env = create_env(task)
|
| 72 |
obs = _env.reset()
|
| 73 |
|
| 74 |
return {
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
@app.post("/step")
|
| 84 |
+
@app.post("/step/")
|
| 85 |
+
def step(payload: Dict[str, Any] = Body(...)):
|
| 86 |
env = get_env()
|
| 87 |
|
| 88 |
try:
|
| 89 |
+
action = payload.get("action")
|
| 90 |
+
if not action:
|
| 91 |
+
raise ValueError("Missing 'action' field")
|
| 92 |
+
|
| 93 |
+
obs, reward, done, info = env.step(action)
|
| 94 |
|
| 95 |
return {
|
| 96 |
"observation": obs,
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
@app.get("/state")
|
| 107 |
+
@app.get("/state/")
|
| 108 |
def state():
|
| 109 |
env = get_env()
|
| 110 |
try:
|