Spaces:
Sleeping
Sleeping
File size: 2,074 Bytes
5451361 84db353 5451361 90df260 86f6bbf 84db353 64b49c0 84db353 c1901f8 84db353 786645d 135b70e 84db353 88a3c14 786645d 135b70e 40b13c1 135b70e f626606 135b70e 40b13c1 1cb6443 135b70e f626606 135b70e f626606 135b70e 1cb6443 135b70e 5451361 135b70e 5451361 84db353 cebb663 90df260 cebb663 90df260 88a3c14 135b70e 88a3c14 cebb663 90df260 cebb663 84db353 5451361 84db353 29fea61 14e4375 29fea61 | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | from fastapi import FastAPI
from pydantic import BaseModel
import random
random.seed(42)
app = FastAPI()
emails = [
{"email": "Refund my order", "label": "support"},
{"email": "Interested in pricing", "label": "sales"},
{"email": "Bug in product", "label": "support"},
{"email": "Partnership request", "label": "business"}
]
state = {}
done = False
class Action(BaseModel):
action: str
@app.get("/")
def root():
return {"status": "ok"}
# ---- TASK 1 ----
@app.post("/reset_easy")
def reset_easy():
global state, done
state = random.choice(emails)
state["task"] = "easy"
done = False
return {"state": state}
# ---- TASK 2 ----
@app.post("/reset_medium")
def reset_medium():
global state, done
state = random.choice(emails)
state["task"] = "medium"
done = False
return {"state": state}
# ---- TASK 3 ----
@app.post("/reset_hard")
def reset_hard():
global state, done
state = random.choice(emails)
state["task"] = "hard"
done = False
return {"state": state}
# ---- TASK 4 ----
@app.post("/reset_expert")
def reset_expert():
global state, done
state = random.choice(emails)
state["task"] = "expert"
done = False
return {"state": state}
# default reset
@app.post("/reset")
def reset():
return reset_easy()
@app.post("/step")
def step(action: Action):
global state, done
correct = action.action == state["label"]
# base reward
base = 0.55 if correct else 0.25
# difficulty bonus
bonus = {
"easy": 0.05,
"medium": 0.1,
"hard": 0.15,
"expert": 0.2
}
reward = base + bonus.get(state["task"], 0)
# add slight stochastic realism
import random
reward += random.uniform(-0.02, 0.02)
# clamp
reward = max(0.05, min(reward, 0.95))
done = True
return {
"state": state,
"reward": reward,
"done": done
}
def main():
import uvicorn
uvicorn.run("server.app:app", host="0.0.0.0", port=7860)
if __name__ == "__main__":
main()
|