File size: 1,382 Bytes
5df9e2a
1b5e9dd
c212549
 
 
 
 
 
acfa9cc
 
 
 
 
 
 
 
 
 
 
 
54a4445
5df9e2a
54a4445
c212549
1b5e9dd
 
 
 
 
 
 
 
 
 
acfa9cc
c212549
 
 
54a4445
1b5e9dd
 
 
 
 
 
 
 
5df9e2a
 
54a4445
1b5e9dd
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
from fastapi import FastAPI, Body
from fastapi.responses import JSONResponse
from env.environment import CustomerSupportEnv
from env.models import Action

app = FastAPI()
env = CustomerSupportEnv()

# ✅ ROOT (IMPORTANT FOR HUGGING FACE VALIDATION)
@app.get("/")
def home():
    return {
        "message": "Customer Support AI is running",
        "endpoints": {
            "reset": "/reset (POST)",
            "step": "/step (POST)"
        }
    }

# 🔹 RESET
@app.post("/reset")
def reset(dummy: dict = Body(default={})):
    obs = env.reset()

    return JSONResponse(content={
        "observation": {
            "customer_query": obs.customer_query,
            "conversation_history": obs.conversation_history,
            "ticket_status": obs.ticket_status,
            "sentiment": obs.sentiment,
            "progress": float(obs.progress)
        }
    })

# 🔹 STEP
@app.post("/step")
def step(action: Action):
    obs, reward, done, info = env.step(action)

    return JSONResponse(content={
        "observation": {
            "customer_query": obs.customer_query,
            "conversation_history": obs.conversation_history,
            "ticket_status": obs.ticket_status,
            "sentiment": obs.sentiment,
            "progress": float(obs.progress)
        },
        "reward": float(reward),
        "done": bool(done),
        "info": info
    })