Skip to content

Commit

Permalink
Updates rasa actions
Browse files Browse the repository at this point in the history
  • Loading branch information
klpanagi committed May 18, 2024
1 parent 0856bf6 commit cef33d4
Showing 1 changed file with 44 additions and 184 deletions.
228 changes: 44 additions & 184 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,256 +43,116 @@ def compute_user_properties(property):
return ''


class Actionaskcourseinfoformformcourseslot(Action):
class Actionaskform1formcityslot(Action):

def name(self) -> Text:
return "action_ask_course_info_form_form_course_slot"
return "action_ask_form1_form_city_slot"

def run(self, dispatcher, tracker, domain):

output = []



dispatcher.utter_message(text = f"Which course do you need information about?")
dispatcher.utter_message(text = f"For which city?")

return output


class Validatecourseinfoformform(FormValidationAction):
class Validateform1form(FormValidationAction):

def name(self) -> Text:
return "validate_course_info_form_form"
return "validate_form1_form"

def extract_info(self, dispatcher, tracker, domain):
def extract_answer(self, dispatcher, tracker, domain):
output = {}
requested_slot = tracker.get_slot('requested_slot')
course_slot = tracker.get_slot('course_slot')
info = tracker.get_slot('info')
if course_slot != None and info == None:
course_slot = tracker.get_slot('course_slot')
city_slot = tracker.get_slot('city_slot')
answer = tracker.get_slot('answer')
if city_slot != None and answer == None:
city_slot = tracker.get_slot('city_slot')
try:
response = requests.get(f"https://university-api.edu/course/info",
headers = {},
params = {'course': f"{course_slot}"}
response = requests.get(f"http://services.issel.ee.auth.gr/general_information/weather_openweather",
headers = {'access_token': 'Q5eJZ8sSLEX6XNmOHyMlWagI'},
params = {'city': f"{city_slot}", 'language': 'English'}
)
info = response.json()['details']
output["info"] = info
answer = response.json()['description']
output["answer"] = answer
except:
print(f'Error retrieving response from https://university-api.edu/course/info with code {response.status_code}.')
print(f'Error retrieving response from http://services.issel.ee.auth.gr/general_information/weather_openweather with code {response.status_code}.')
dispatcher.utter_message(text = "Apologies, something went wrong.")
return output

class Actionprovidecourseinfo(Action):

def name(self) -> Text:
return "action_provide_course_info"

def run(self, dispatcher, tracker, domain):

output = []

info = tracker.get_slot('info')
course_slot = tracker.get_slot('course_slot')


dispatcher.utter_message(text = f"The information for the { course_slot } course is: { info }")

output.append(SlotSet('course_slot', None))
output.append(SlotSet('info', None))
return output

class Actionaskcourseregisterformformcourseslot(Action):

def name(self) -> Text:
return "action_ask_course_register_form_form_course_slot"

def run(self, dispatcher, tracker, domain):

output = []



dispatcher.utter_message(text = f"Which course do you want to register for?")

return output


class Validatecourseregisterformform(FormValidationAction):

def name(self) -> Text:
return "validate_course_register_form_form"

def extract_confirmation(self, dispatcher, tracker, domain):
def extract_answer2(self, dispatcher, tracker, domain):
output = {}
requested_slot = tracker.get_slot('requested_slot')
course_slot = tracker.get_slot('course_slot')
confirmation = tracker.get_slot('confirmation')
if course_slot != None and confirmation == None:
course_slot = tracker.get_slot('course_slot')
answer = tracker.get_slot('answer')
answer2 = tracker.get_slot('answer2')
if answer != None and answer2 == None:
answer = tracker.get_slot('answer')
city_slot = tracker.get_slot('city_slot')
city = f"{ city_slot }"
language = f"English"
try:
response = requests.post(f"https://university-api.edu/course/register",
headers = {},
data = {'course': f"{course_slot}"},
response = requests.get(f"http://services.issel.ee.auth.gr/general_information/weather_openweather/{city}/{language}",
headers = {'access_token': 'Q5eJZ8sSLEX6XNmOHyMlWagI'},
params = {}
)
confirmation = response.json()['status']
output["confirmation"] = confirmation
answer2 = response.json()['temp']
output["answer2"] = answer2
except:
print(f'Error retrieving response from https://university-api.edu/course/register with code {response.status_code}.')
print(f'Error retrieving response from http://services.issel.ee.auth.gr/general_information/weather_openweather/{city}/{language} with code {response.status_code}.')
dispatcher.utter_message(text = "Apologies, something went wrong.")
return output

class Actionconfirmregistration(Action):
class Actionanswerback(Action):

def name(self) -> Text:
return "action_confirm_registration"
return "action_answer_back"

def run(self, dispatcher, tracker, domain):

output = []

confirmation = tracker.get_slot('confirmation')
course_slot = tracker.get_slot('course_slot')
answer = tracker.get_slot('answer')
answer2 = tracker.get_slot('answer2')
city_slot = tracker.get_slot('city_slot')


dispatcher.utter_message(text = f"You have been registered for the { course_slot } course. Status: { confirmation }")
dispatcher.utter_message(text = f"The weather for { city_slot } is { answer } with { answer2 } degrees")

output.append(SlotSet('course_slot', None))
output.append(SlotSet('confirmation', None))
output.append(SlotSet('city_slot', None))
output.append(SlotSet('answer', None))
output.append(SlotSet('answer2', None))
return output

class Actionaskappointmentformformfacultyslot(Action):

def name(self) -> Text:
return "action_ask_appointment_form_form_faculty_slot"

def run(self, dispatcher, tracker, domain):

output = []



dispatcher.utter_message(text = f"Which faculty member would you like to meet?")

return output


class Validateappointmentformform(FormValidationAction):

def name(self) -> Text:
return "validate_appointment_form_form"

def extract_confirmation(self, dispatcher, tracker, domain):
output = {}
requested_slot = tracker.get_slot('requested_slot')
faculty_slot = tracker.get_slot('faculty_slot')
confirmation = tracker.get_slot('confirmation')
if faculty_slot != None and confirmation == None:
faculty_slot = tracker.get_slot('faculty_slot')
try:
response = requests.post(f"https://university-api.edu/faculty/appointment",
headers = {},
data = {'faculty': f"{faculty_slot}"},
params = {}
)
confirmation = response.json()['status']
output["confirmation"] = confirmation
except:
print(f'Error retrieving response from https://university-api.edu/faculty/appointment with code {response.status_code}.')
dispatcher.utter_message(text = "Apologies, something went wrong.")
return output

class Actionconfirmappointment(Action):

def name(self) -> Text:
return "action_confirm_appointment"

def run(self, dispatcher, tracker, domain):

output = []

faculty_slot = tracker.get_slot('faculty_slot')
confirmation = tracker.get_slot('confirmation')


dispatcher.utter_message(text = f"Your appointment with { faculty_slot } has been scheduled. Status: { confirmation }")

output.append(SlotSet('faculty_slot', None))
output.append(SlotSet('confirmation', None))
return output

class Actionaskeventinfoformformeventslot(Action):

def name(self) -> Text:
return "action_ask_event_info_form_form_event_slot"

def run(self, dispatcher, tracker, domain):

output = []



dispatcher.utter_message(text = f"Which event do you need information about?")

return output


class Validateeventinfoformform(FormValidationAction):

def name(self) -> Text:
return "validate_event_info_form_form"

def extract_info(self, dispatcher, tracker, domain):
output = {}
requested_slot = tracker.get_slot('requested_slot')
event_slot = tracker.get_slot('event_slot')
info = tracker.get_slot('info')
if event_slot != None and info == None:
event_slot = tracker.get_slot('event_slot')
try:
response = requests.get(f"https://university-api.edu/event/info",
headers = {},
params = {'event': f"{event_slot}"}
)
info = response.json()['details']
output["info"] = info
except:
print(f'Error retrieving response from https://university-api.edu/event/info with code {response.status_code}.')
dispatcher.utter_message(text = "Apologies, something went wrong.")
return output

class Actionprovideeventinfo(Action):
class Actiongreetback(Action):

def name(self) -> Text:
return "action_provide_event_info"
return "action_greet_back"

def run(self, dispatcher, tracker, domain):

output = []

event_slot = tracker.get_slot('event_slot')
info = tracker.get_slot('info')


dispatcher.utter_message(text = f"The information for the { event_slot } event is: { info }")
dispatcher.utter_message(text = f"Hello there!!!")

output.append(SlotSet('event_slot', None))
output.append(SlotSet('info', None))
return output

class Actiongreetback(Action):
class Actionrespondiambot(Action):

def name(self) -> Text:
return "action_greet_back"
return "action_respond_iambot"

def run(self, dispatcher, tracker, domain):

output = []



dispatcher.utter_message(text = f"Hello! How can I assist you today?")
dispatcher.utter_message(text = f"I am a bot, powered by dFlow and Rasa.")

return output

0 comments on commit cef33d4

Please sign in to comment.