File size: 1,937 Bytes
2414d31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657f0fa
2414d31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
End-to-end test through ClarifyClient (the path TRL training actually uses).

Server stays a single env instance per WebSocket session; reset+step+state
all share state. Run uvicorn first, then this script.
"""

import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))

from client import ClarifyClient


def main() -> int:
    env = ClarifyClient(base_url="http://127.0.0.1:7860").sync()
    with env:
        print("--- list tools ---")
        tools = env.list_tools()
        print([t.name for t in tools])

        print("\n--- reset(seed=7, task_id=medium) ---")
        obs = env.reset(seed=7, task_id="medium")
        print(f"reward={obs.reward}  done={obs.done}")
        print("observation:", obs.observation)

        print("\n--- ask_question: order id ---")
        result = env.call_tool("ask_question", question="what is the order id?")
        print("result:", result)

        print("\n--- ask_question: item issue ---")
        result = env.call_tool("ask_question", question="what's wrong with the order?")
        print("result:", result)

        print("\n--- ask_question: refund/replace ---")
        result = env.call_tool("ask_question", question="refund or replace?")
        print("result:", result)

        print("\n--- ask_question: urgency ---")
        result = env.call_tool("ask_question", question="when do you need this?")
        print("result:", result)

        print("\n--- propose_plan ---")
        plan = json.dumps({
            "order_id": "#4521",
            "item_issue": "wrong-item",
            "refund_or_replace": "replace",
            "urgency": "high",
        })
        result = env.call_tool("propose_plan", plan=plan)
        print("result:", result)

        print("\n--- final state ---")
        state = env.state()
        print(state)

    return 0


if __name__ == "__main__":
    sys.exit(main())