Spaces:
Sleeping
Sleeping
Update actions/actions.py
Browse files- actions/actions.py +56 -19
actions/actions.py
CHANGED
|
@@ -4,24 +4,61 @@
|
|
| 4 |
# See this guide on how to implement these action:
|
| 5 |
# https://rasa.com/docs/rasa/custom-actions
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# See this guide on how to implement these action:
|
| 5 |
# https://rasa.com/docs/rasa/custom-actions
|
| 6 |
|
| 7 |
+
from typing import Any, Text, Dict, List
|
| 8 |
+
from rasa_sdk import Action, Tracker
|
| 9 |
+
from rasa_sdk.events import SlotSet, FollowupAction
|
| 10 |
+
from rasa_sdk.executor import CollectingDispatcher
|
| 11 |
+
import random
|
| 12 |
|
| 13 |
+
class GeneralHelp(Action):
|
| 14 |
+
def name(self) -> Text:
|
| 15 |
+
return "action_general_help"
|
| 16 |
|
| 17 |
+
def run(self, dispatcher: CollectingDispatcher,
|
| 18 |
+
tracker: Tracker,
|
| 19 |
+
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
|
| 20 |
+
|
| 21 |
+
user_role = tracker.slots.get("user_role", None)
|
| 22 |
+
|
| 23 |
+
if user_role is None:
|
| 24 |
+
dispatcher.utter_message(text="Sure! Are you a developer or a client representing an organization?")
|
| 25 |
+
else:
|
| 26 |
+
return [FollowupAction("action_help_with_role")]
|
| 27 |
+
|
| 28 |
+
# Modified from @Rohit Garg's code https://github.com/rohitkg83/Omdena/blob/master/actions/actions.py
|
| 29 |
+
class ActionHelpWithRole(Action):
|
| 30 |
+
|
| 31 |
+
def name(self) -> Text:
|
| 32 |
+
return "action_help_with_role"
|
| 33 |
+
|
| 34 |
+
def run(self,
|
| 35 |
+
dispatcher: CollectingDispatcher,
|
| 36 |
+
tracker: Tracker,
|
| 37 |
+
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
|
| 38 |
+
|
| 39 |
+
# Get the value of the first_occurrence_user_type slot
|
| 40 |
+
current_user_type = tracker.slots.get("user_role", None)
|
| 41 |
+
|
| 42 |
+
if current_user_type == 'developer':
|
| 43 |
+
msg = "Thanks a lot for providing the details. You can join one of our local chapter and collaborate on " \
|
| 44 |
+
"various projects and challenges to Develop Your Skills, Get Recognized, and Make an Impact. Please " \
|
| 45 |
+
"visit https://omdena.com/community for more details. Do you have any other questions? "
|
| 46 |
+
|
| 47 |
+
elif current_user_type == 'client':
|
| 48 |
+
msg = "Thanks a lot for providing the details. With us you can Innovate, Deploy and Scale " \
|
| 49 |
+
"AI Solutions in Record Time. For more details please visit https://omdena.com/offerings. Do you have any other questions? "
|
| 50 |
+
else:
|
| 51 |
+
msg = "Please enter either developer or client"
|
| 52 |
+
|
| 53 |
+
dispatcher.utter_message(text=msg)
|
| 54 |
+
|
| 55 |
+
class ResetSlotsAction(Action):
|
| 56 |
+
def name(self) -> Text:
|
| 57 |
+
return "action_reset_slots"
|
| 58 |
+
|
| 59 |
+
def run(self, dispatcher: CollectingDispatcher,
|
| 60 |
+
tracker: Tracker,
|
| 61 |
+
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
|
| 62 |
+
slots_to_reset = ["user_role"] # Add the names of the slots you want to reset
|
| 63 |
+
events = [SlotSet(slot, None) for slot in slots_to_reset]
|
| 64 |
+
return events
|