-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.py
More file actions
55 lines (44 loc) · 1.64 KB
/
env.py
File metadata and controls
55 lines (44 loc) · 1.64 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
from dataset import dataset, easy_tasks, medium_tasks
from agent import agent
from evaluator import evaluate
class CustomerSupportEnv:
def __init__(self):
self.index = 0
self.data = dataset
self.current_ticket = None
self.easy_ids = list(range(len(easy_tasks)))
self.medium_ids = list(range(len(easy_tasks), len(easy_tasks) + len(medium_tasks)))
def _get_difficulty(self, idx):
if idx in self.easy_ids:
return "easy"
elif idx in self.medium_ids:
return "medium"
return "hard"
def reset(self):
self.index = 0
self.current_ticket = self.data[self.index]["ticket"]
from models import State
return State(ticket=self.current_ticket)
def step(self, action=None):
output = action if action else agent(self.current_ticket)
correct = self.data[self.index]
difficulty = self._get_difficulty(self.index)
reward = evaluate(output, correct, difficulty)
self.index += 1
done = self.index >= len(self.data)
if not done:
next_ticket = self.data[self.index]["ticket"]
self.current_ticket = next_ticket
else:
next_ticket = None
from models import Action, State
action_obj = Action(
issue=output["issue"],
action=output["action"],
reply=output["reply"]
)
next_state = State(ticket=next_ticket) if next_ticket else None
return next_state, reward, done, {"action": action_obj}
def state(self):
from models import State
return State(ticket=self.current_ticket)