-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference.py
More file actions
76 lines (61 loc) · 2.68 KB
/
Copy pathinference.py
File metadata and controls
76 lines (61 loc) · 2.68 KB
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
import os
from env import CustomerSupportEnv
API_BASE_URL = os.getenv("API_BASE_URL")
MODEL_NAME = os.getenv("MODEL_NAME")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def mock_agent(ticket):
ticket_lower = ticket.lower()
if any(w in ticket_lower for w in ["charge", "payment", "refund", "money", "billed", "overcharged", "deducted"]):
issue, action = "billing", "refund"
elif any(w in ticket_lower for w in ["ship", "deliver", "arrival", "late", "stuck", "delay", "arrived"]):
issue, action = "shipping", "escalate"
else:
issue, action = "product", "replace"
return {
"issue": issue,
"action": action,
"reply": f"We are sorry for the inconvenience. We will {action} this for you shortly."
}
def run_inference():
print("[START] Running inference")
print(f"[CONFIG] API key set: {bool(OPENAI_API_KEY)}")
if OPENAI_API_KEY:
from agent import agent
active_agent = agent
print("[CONFIG] Using real agent")
else:
active_agent = mock_agent
print("[CONFIG] No API key found — using mock agent for reproducible baseline")
env = CustomerSupportEnv()
state = env.reset()
total_reward = 0
steps = 0
easy_scores, medium_scores, hard_scores = [], [], []
done = False
while not done:
print(f"\n[STEP {steps + 1}] Ticket: {state.ticket}")
action = active_agent(state.ticket)
difficulty = env._get_difficulty(env.index)
state, reward, done, info = env.step(action)
print(f"[STEP {steps + 1}] Difficulty : {difficulty}")
print(f"[STEP {steps + 1}] Issue : {action['issue']}")
print(f"[STEP {steps + 1}] Action : {action['action']}")
print(f"[STEP {steps + 1}] Reply : {action['reply']}")
print(f"[STEP {steps + 1}] Reward : {reward:.2f}")
total_reward += reward
steps += 1
if difficulty == "easy":
easy_scores.append(reward)
elif difficulty == "medium":
medium_scores.append(reward)
else:
hard_scores.append(reward)
final_score = total_reward / steps
print(f"\n[RESULTS] ----------------------------------------")
print(f" Easy avg : {sum(easy_scores)/len(easy_scores):.2f} (over {len(easy_scores)} tickets)")
print(f" Medium avg : {sum(medium_scores)/len(medium_scores):.2f} (over {len(medium_scores)} tickets)")
print(f" Hard avg : {sum(hard_scores)/len(hard_scores):.2f} (over {len(hard_scores)} tickets)")
print(f" Overall : {final_score:.2f} (over {steps} tickets)")
print(f"[END] -----------------------------------------------")
if __name__ == "__main__":
run_inference()