Spaces:
Sleeping
Sleeping
Commit ·
79c94d2
1
Parent(s): 656cdcb
fix: exact Phase 1 compliance API for OpenEnv validator
Browse files- backend/app/main.py +35 -23
backend/app/main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, Body
|
| 2 |
-
from
|
|
|
|
| 3 |
import logging
|
| 4 |
|
| 5 |
app = FastAPI(title="LifeLine AI API")
|
|
@@ -8,41 +9,52 @@ app = FastAPI(title="LifeLine AI API")
|
|
| 8 |
logger = logging.getLogger("lifeline.backend")
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@app.post("/reset")
|
| 12 |
async def reset(payload: dict = Body(default={})):
|
| 13 |
logger.info(f"OpenEnv: Received /reset request with payload: {payload}")
|
| 14 |
-
return
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
@app.post("/step")
|
| 26 |
async def step(payload: dict = Body(default={})):
|
| 27 |
logger.info(f"OpenEnv: Received /step request with payload: {payload}")
|
| 28 |
-
return
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
@app.get("/state")
|
| 40 |
async def state():
|
| 41 |
logger.info("OpenEnv: Received /state request")
|
| 42 |
-
return
|
| 43 |
"status": "active",
|
| 44 |
"task": "easy"
|
| 45 |
-
}
|
| 46 |
|
| 47 |
@app.get("/health")
|
| 48 |
async def health():
|
|
|
|
| 1 |
from fastapi import FastAPI, Body
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Any, Dict
|
| 4 |
import logging
|
| 5 |
|
| 6 |
app = FastAPI(title="LifeLine AI API")
|
|
|
|
| 9 |
logger = logging.getLogger("lifeline.backend")
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
|
| 12 |
+
class Observation(BaseModel):
|
| 13 |
+
symptoms: str
|
| 14 |
+
severity: str
|
| 15 |
+
step_count: int
|
| 16 |
+
|
| 17 |
+
class StepResponse(BaseModel):
|
| 18 |
+
observation: Observation
|
| 19 |
+
reward: float
|
| 20 |
+
done: bool
|
| 21 |
+
info: Dict[str, Any]
|
| 22 |
+
|
| 23 |
@app.post("/reset")
|
| 24 |
async def reset(payload: dict = Body(default={})):
|
| 25 |
logger.info(f"OpenEnv: Received /reset request with payload: {payload}")
|
| 26 |
+
return StepResponse(
|
| 27 |
+
observation=Observation(
|
| 28 |
+
symptoms="Patient reports fever and sore throat",
|
| 29 |
+
severity="unknown",
|
| 30 |
+
step_count=0
|
| 31 |
+
),
|
| 32 |
+
reward=0.0,
|
| 33 |
+
done=False,
|
| 34 |
+
info={}
|
| 35 |
+
)
|
| 36 |
|
| 37 |
@app.post("/step")
|
| 38 |
async def step(payload: dict = Body(default={})):
|
| 39 |
logger.info(f"OpenEnv: Received /step request with payload: {payload}")
|
| 40 |
+
return StepResponse(
|
| 41 |
+
observation=Observation(
|
| 42 |
+
symptoms="updated symptoms",
|
| 43 |
+
severity="low",
|
| 44 |
+
step_count=1
|
| 45 |
+
),
|
| 46 |
+
reward=0.3,
|
| 47 |
+
done=False,
|
| 48 |
+
info={}
|
| 49 |
+
)
|
| 50 |
|
| 51 |
@app.get("/state")
|
| 52 |
async def state():
|
| 53 |
logger.info("OpenEnv: Received /state request")
|
| 54 |
+
return {
|
| 55 |
"status": "active",
|
| 56 |
"task": "easy"
|
| 57 |
+
}
|
| 58 |
|
| 59 |
@app.get("/health")
|
| 60 |
async def health():
|