Spaces:
Sleeping
Sleeping
File size: 1,090 Bytes
78940a4 583360d 78940a4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | from fastapi import FastAPI
from pydantic import BaseModel, Field
from typing import Dict, Any
from env.environment import EmailTriageEnv
app = FastAPI()
env = EmailTriageEnv()
@app.get("/")
async def root():
return {
"name": "Email Triage OpenEnv",
"status": "running",
"instructions": "Use POST /reset and POST /step to interact with this environment."
}
class ResetRequest(BaseModel):
task: str = "easy"
class StepRequest(BaseModel):
action: Dict[str, Any] = Field(default_factory=dict)
@app.post("/reset")
async def reset_env(req: ResetRequest):
obs, info = await env.reset(req.task)
return {
"observation": obs.model_dump(),
"info": info
}
@app.post("/step")
async def step_env(req: StepRequest):
obs, reward, done, info = await env.step(req.action)
return {
"observation": obs.model_dump() if obs else None,
"reward": float(reward),
"done": bool(done),
"info": info
}
@app.get("/state")
async def get_state():
state = env.state()
return state.model_dump()
|