File size: 1,623 Bytes
bbe2ae8
b2896f3
bbe2ae8
 
 
 
 
91f67db
b2896f3
 
bbe2ae8
b2896f3
bbe2ae8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import asyncio
import os

from client import CustomerSupportEnvClient
from models import SupportAction


BASE_URL = os.getenv("TARGET_BASE_URL", "https://krishdev99-openenvscaler.hf.space")


async def run_episode(difficulty: str, index: int) -> dict:
    env = CustomerSupportEnvClient(base_url=BASE_URL)
    await env.connect()
    reset_result = await env.reset(difficulty=difficulty, index=index)

    rewards: list[float] = []
    done = bool(reset_result.done)
    observation = reset_result.observation

    actions = [
        SupportAction(action_type="classify", content="technical_issue"),
        SupportAction(action_type="search_kb", content=observation.kb_id),
        SupportAction(
            action_type="respond",
            content="Thank you for contacting us. We will assist you shortly.",
        ),
    ]

    for action in actions:
        if done:
            break
        step_result = await env.step(action)
        rewards.append(float(step_result.reward or 0.0))
        done = bool(step_result.done)
        observation = step_result.observation

    await env.close()
    return {
        "difficulty": difficulty,
        "index": index,
        "ticket_id": observation.ticket_id,
        "done": done,
        "steps": len(rewards),
        "reward_sum": round(sum(rewards), 4),
    }


async def main() -> None:
    for difficulty in ("easy", "medium", "hard"):
        for index in (0, 1):
            result = await run_episode(difficulty, index)
            print(result)


if __name__ == "__main__":
    asyncio.run(main())