Spaces:
Runtime error
Runtime error
Download api.py from pawan2007/email_support: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/pawan2007/email_support/resolve/main/api.py
- Command line
-
hf download hf://spaces/pawan2007/email_support/api.py
-
curl -L -o api.py https://huggingface.co/spaces/pawan2007/email_support/resolve/main/api.py
1.58 kB
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from env.customer_env import CustomerEnv | |
| app = FastAPI( | |
| title="🚀 Customer Support OpenEnv API", | |
| description="RL-based Email Support Environment", | |
| version="1.0" | |
| ) | |
| env = CustomerEnv() | |
| # -------- Models -------- | |
| class ActionRequest(BaseModel): | |
| action: int | |
| # -------- Endpoints -------- | |
| def home(): | |
| return { | |
| "message": "🚀 Customer Support OpenEnv API is running", | |
| "docs": "/docs", | |
| "endpoints": [ | |
| "/reset", | |
| "/step", | |
| "/state", | |
| "/tasks", | |
| "/grader", | |
| "/baseline" | |
| ] | |
| } | |
| def reset(): | |
| state = env.reset() | |
| return {"state": state} | |
| def step(req: ActionRequest): | |
| if env.state is None: | |
| env.reset() | |
| state, reward, done, _ = env.step(req.action) | |
| return { | |
| "state": state, | |
| "reward": reward, | |
| "done": done | |
| } | |
| def state(): | |
| return {"state": env.state} | |
| def tasks(): | |
| return { | |
| "tasks": [ | |
| "Fix grammar", | |
| "Make email formal", | |
| "Shorten email", | |
| "Expand email" | |
| ] | |
| } | |
| def grader(req: ActionRequest): | |
| if req.action == 1: | |
| return {"score": 1, "feedback": "Good action"} | |
| return {"score": 0, "feedback": "Bad action"} | |
| def baseline(): | |
| return { | |
| "default_action": 1, | |
| "description": "Always choose formal tone" | |
| } |