Spaces:
Configuration error
Configuration error
File size: 1,218 Bytes
fc163a0 | 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 47 | from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Dict, Optional, List
from env import EmailEnv
from models import Action, Observation
import uvicorn
app = FastAPI(title="EmailTriage OpenEnv", description="A real-world email management and scheduling environment.")
# Global instance
env = EmailEnv()
class ResetRequest(BaseModel):
task_id: int = 1
@app.post("/reset")
async def reset_env(req: ResetRequest):
# Mapping task_id to levels 1, 2, 3
obs, info = env.reset(options={"level": req.task_id})
return {
"observation": obs,
"info": info,
"status": "Ready"
}
@app.post("/step")
async def step_env(action: Dict):
"""
OpenEnv compliant step logic using Pydantic action models.
"""
obs, reward, terminated, truncated, info = env.step(action)
return {
"observation": obs,
"reward": float(reward),
"terminated": bool(terminated),
"truncated": bool(truncated),
"info": info
}
@app.get("/state")
async def get_state():
"""State API for debugging and grading."""
return env.state()
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
|