Spaces:
Sleeping
Sleeping
File size: 5,614 Bytes
5447b31 26763bc 5447b31 26763bc 5447b31 26763bc 37fef8c 7682cdd e582175 7682cdd |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, FollowupAction
from rasa_sdk.executor import CollectingDispatcher
import random
class GeneralHelp(Action):
def name(self) -> Text:
return "action_general_help"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_role = tracker.slots.get("user_role", None)
if user_role is None:
dispatcher.utter_message(text="Sure! Are you a developer or a client representing an organization?")
else:
return [FollowupAction("action_help_with_role")]
# Modified from @Rohit Garg's code https://github.com/rohitkg83/Omdena/blob/master/actions/actions.py
class ActionHelpWithRole(Action):
def name(self) -> Text:
return "action_help_with_role"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Get the value of the first_occurrence_user_type slot
current_user_type = tracker.slots.get("user_role", None)
if current_user_type == 'developer':
msg = "Thanks a lot for providing the details. You can join one of our local chapter and collaborate on " \
"various projects and challenges to Develop Your Skills, Get Recognized, and Make an Impact. Please " \
"visit https://omdena.com/community for more details. Do you have any other questions? "
elif current_user_type == 'client':
msg = "Thanks a lot for providing the details. With us you can Innovate, Deploy and Scale " \
"AI Solutions in Record Time. For more details please visit https://omdena.com/offerings. Do you have any other questions? "
else:
msg = "Please enter either developer or client"
dispatcher.utter_message(text=msg)
class ResetSlotsAction(Action):
def name(self) -> Text:
return "action_reset_slots"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
slots_to_reset = ["user_role"] # Add the names of the slots you want to reset
events = [SlotSet(slot, None) for slot in slots_to_reset]
return events
class ActionJoinClassify(Action):
def name(self) -> Text:
return "action_join_classify"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Get the value of the latest intent
last_intent = tracker.slots.get("local_chapter", None)
# Check if the last intent was 'local_chapter'
if last_intent == 'local chapter':
dispatcher.utter_message(template="utter_join_chapter")
else:
msg = "I'm sorry, I didnt understand your question, Could you please rephrase?"
dispatcher.utter_message(text=msg)
class ActionEligibilityClassify(Action):
def name(self) -> Text:
return "action_eligibility_classify"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Get the value of the latest intent
last_intent = tracker.slots.get("local_chapter", None)
# Check if the last intent was 'local_chapter'
if last_intent == 'local chapter':
dispatcher.utter_message(template="utter_local_chapter_participation_eligibility")
else:
msg = "I'm sorry, I didn't understand your question. Could you please rephrase?"
dispatcher.utter_message(text=msg)
class ActionCostClassify(Action):
def name(self) -> Text:
return "action_cost_classify"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Get the value of the latest intent
last_intent = tracker.slots.get("local_chapter", None)
# Check if the last intent was 'local_chapter'
if last_intent == 'local chapter':
dispatcher.utter_message(template="utter_local_chapter_cost")
else:
msg = "I'm sorry, I didn't understand your question. Could you please rephrase?"
dispatcher.utter_message(text=msg)
class SayHelloWorld(Action):
def name(self) -> Text:
return "action_hello_world"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
# Use OpenAI API to generate a response
secret_value_0 = os.environ.get("openai")
openai.api_key = secret_value_0
model_engine = "text-davinci-002"
prompt_template = "Say hello world"
response = openai.Completion.create(
engine=model_engine,
prompt=prompt_template,
max_tokens=124,
temperature=0.8,
n=1,
stop=None,
)
# Output the generated response to user
generated_text = response.choices[0].text
dispatcher.utter_message(text=generated_text) |