File size: 1,105 Bytes
92fefbd
93be568
92fefbd
95bd967
d833e0f
93be568
92fefbd
7dd1e30
92fefbd
7dd1e30
92fefbd
95bd967
92fefbd
 
7dd1e30
92fefbd
 
7dd1e30
92fefbd
d833e0f
7dd1e30
 
92fefbd
 
7dd1e30
92fefbd
7dd1e30
 
d833e0f
7dd1e30
 
 
 
92fefbd
 
 
 
 
 
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
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional
from env.tasks import load_task

app = FastAPI()
state = {"current_task": None}

class Action(BaseModel):
    action_type: str
    content: Optional[str] = ""

@app.get("/")
def health(): return {"status": "running"}

@app.post("/reset")
async def reset(task: str = "easy_refund"):
    global state
    task_data = load_task(task)[0]
    state["current_task"] = task_data
    return {"observation": task_data["text"], "task_id": task}

@app.post("/step")
async def step(action: Action):
    global state
    t = state.get("current_task")
    if not t: return {"reward": 0.05, "done": True, "error": "No task"}
    
    # Logic: If agent mentions the keyword, give partial reward
    success = t["target"] in action.content.lower() or action.action_type == "solve"
    reward = t["reward_weight"] if success else 0.15
    return {"observation": "Processed", "reward": reward, "done": True, "error": None}

def main():
    uvicorn.run(app, host="0.0.0.0", port=7860)

if __name__ == "__main__":
    main()