-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
actions.py
67 lines (51 loc) · 2.06 KB
/
actions.py
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
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
class ActionSearchConcerts(Action):
def name(self):
return "action_search_concerts"
def run(self, dispatcher, tracker, domain):
concerts = [
{"artist": "Foo Fighters", "reviews": 4.5},
{"artist": "Katy Perry", "reviews": 5.0},
]
description = ", ".join([c["artist"] for c in concerts])
dispatcher.utter_message(text=f"{description}")
return [SlotSet("concerts", concerts)]
class ActionSearchVenues(Action):
def name(self):
return "action_search_venues"
def run(self, dispatcher, tracker, domain):
venues = [
{"name": "Big Arena", "reviews": 4.5},
{"name": "Rock Cellar", "reviews": 5.0},
]
dispatcher.utter_message(text="here are some venues I found")
description = ", ".join([c["name"] for c in venues])
dispatcher.utter_message(text=f"{description}")
return [SlotSet("venues", venues)]
class ActionShowConcertReviews(Action):
def name(self):
return "action_show_concert_reviews"
def run(self, dispatcher, tracker, domain):
concerts = tracker.get_slot("concerts")
dispatcher.utter_message(text=f"concerts from slots: {concerts}")
return []
class ActionShowVenueReviews(Action):
def name(self):
return "action_show_venue_reviews"
def run(self, dispatcher, tracker, domain):
venues = tracker.get_slot("venues")
dispatcher.utter_message(text=f"venues from slots: {venues}")
return []
class ActionSetMusicPreference(Action):
def name(self):
return "action_set_music_preference"
def run(self, dispatcher, tracker, domain):
"""Sets the slot 'likes_music' to true/false dependent on whether the user
likes music"""
intent = tracker.latest_message["intent"].get("name")
if intent == "affirm":
return [SlotSet("likes_music", True)]
elif intent == "deny":
return [SlotSet("likes_music", False)]
return []