jananiprakash152519's picture
Update server/app.py
62b9676 verified
Raw History Blame Contribute Delete
1.16 kB
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
app = FastAPI()
class Action(BaseModel):
action: str
class SimpleEnv:
def __init__(self):
self.step_count = 0
self.done = False
def reset(self):
self.step_count = 0
self.done = False
return {"observation": "Classify emails using classify(id, label)"}
def step(self, action):
self.step_count += 1
reward = 0.0
error = None
if "classify" in action:
reward = 0.5
else:
reward = -0.2
error = "invalid_action"
if self.step_count >= 3:
self.done = True
reward = 1.0
return {
"observation": "Next step",
"reward": reward,
"done": self.done,
"info": {"error": error}
}
env = SimpleEnv()
@app.post("/reset")
def reset():
return env.reset()
@app.post("/step")
def step(action: Action):
return env.step(action.action)
@app.get("/")
def root():
return {"status": "running"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)