From 69187afa300db14ffd6a864ae0cba4c270af1ebc Mon Sep 17 00:00:00 2001 From: cdhiraj40 Date: Tue, 20 Sep 2022 06:57:21 +0530 Subject: [PATCH 1/7] Improved start recording and ask car number actions with better replies. --- .../car_selection_actions/action_ask_car_number.py | 6 ++++++ .../validate_car_selection_form.py | 14 +++----------- .../action_start_recording.py | 10 +++++----- data/rules.yml | 10 ++++++++++ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/actions/car_selection_actions/action_ask_car_number.py b/actions/car_selection_actions/action_ask_car_number.py index c915e59..e2e417c 100644 --- a/actions/car_selection_actions/action_ask_car_number.py +++ b/actions/car_selection_actions/action_ask_car_number.py @@ -65,6 +65,12 @@ def run( "action": response.action.as_dict(), "data": response.data }) + else: + # return a message and deactive the form + print(f"{self.name()}: User is not on car selection or dashboard screen") + dispatcher.utter_message( + text="User is not on car selection or dashboard screen") + return [ActiveLoop(None), SlotSet('car_number', None)] # else: # return a message and deactive the form # print(f"{self.name()}: {metadata['type']} is not CAR_SELECTION") diff --git a/actions/car_selection_actions/validate_car_selection_form.py b/actions/car_selection_actions/validate_car_selection_form.py index 2577882..f0089e6 100644 --- a/actions/car_selection_actions/validate_car_selection_form.py +++ b/actions/car_selection_actions/validate_car_selection_form.py @@ -53,7 +53,7 @@ def validate_car_number( # if s if slot_value.lower() not in ALLOWED_CAR_NUMBER: response = car_utils.return_response( - "Please specify a correct number that is one, two or three") + "Please specify a correct number that is first, second, or third") dispatcher.utter_message(json_message={ "query": response.query, "reply": response.reply, @@ -78,7 +78,7 @@ def validate_car_number( return {"car_number": None, "next_car": True, "previous_car": False, "select_car_iteration": return_select_car_iteration} if slot_value.lower() == "previous" and select_car_iteration == 0: - response = car_utils.return_response(available_message) + response = car_utils.return_response("You are on the first list, you can't go previous") dispatcher.utter_message(json_message={ "query": response.query, "reply": response.reply, @@ -115,11 +115,6 @@ def validate_car_verification( """Validate `car_number` value.""" print("Slot Value", slot_value) - intent = None - try: - intent = tracker.latest_message['intent'].get('name') - except KeyError: - print(f"No intent, something went wrong, error:{Exception}") select_car_iteration = tracker.get_slot("select_car_iteration") metadata = tracker.latest_message.get("metadata") @@ -136,7 +131,7 @@ def validate_car_verification( response = car_utils.return_response(available_message) dispatcher.utter_message(json_message={ "query": response.query, - "reply": response.reply, + "reply": f"Okay reverting the last decision, {response.reply}", "action": response.action.as_dict(), "data": response.data }) @@ -181,13 +176,10 @@ def validate_car_selection(self, dispatcher: CollectingDispatcher, slot_value: s # TODO: new function -> reset only car selection related slots if slot_value == "third" and len(available_cars) >= 3: - # dispatcher.utter_message(text=f"{available_cars[2]} car is available") return {"car_number": "third", "car_name": available_cars[2]} if slot_value == "second" and len(available_cars) >= 2: - # dispatcher.utter_message(text=f"{available_cars[1]} car is available") return {"car_number": "second", "car_name": available_cars[1]} if slot_value == "first" and len(available_cars) >= 1: - # dispatcher.utter_message(text=f"{available_cars[0]} car is available") return {"car_number": "first", "car_name": available_cars[0]} print(f"{self.name()}: Something went wrong with validating car selection and assigning 'car_name' slot.") diff --git a/actions/start_recording_actions/action_start_recording.py b/actions/start_recording_actions/action_start_recording.py index 0371285..65b74f2 100644 --- a/actions/start_recording_actions/action_start_recording.py +++ b/actions/start_recording_actions/action_start_recording.py @@ -158,14 +158,14 @@ def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[T text="Wrong Recording state, Something went wrong!") return [SlotSet("recording_start_query", False)] else: - reply = "Recording is already running! Navigating to recording screen" + reply = "User is not on dashboard screen, Please navigate to Dashboard screen and ask start recording again." nav_to_recording_screen(dispatcher, message, reply, intent) return [SlotSet("recording_start_query", False)] else: - print(f"{self.name()}: No Recording going on!") - dispatcher.utter_message( - text="There is currently no Recording going on") - return [] + print(f"{self.name()}: Recording already going on!") + reply = "Recording is already running! Navigating to recording screen" + nav_to_recording_screen(dispatcher, message, reply, intent) + return [SlotSet("recording_start_query", False)] # else: # print(f" {self.name()}: {metadata['type']} is not RECORDING") # dispatcher.utter_message( diff --git a/data/rules.yml b/data/rules.yml index c9bf101..5c77c2d 100644 --- a/data/rules.yml +++ b/data/rules.yml @@ -13,6 +13,8 @@ rules: - action: utter_iamabot - rule: Run a followup start action anytime the user affirms + condition: + - active_loop: null steps: - intent: affirm - action: action_followup @@ -52,4 +54,12 @@ rules: - active_loop: null - slot_was_set: - requested_slot: null + - action: action_car_selection + + - rule: Select a car whenever user affirms in car selection form + condition: + - active_loop: car_selection_form + steps: + - slot_was_set: + - car_verification: yes - action: action_car_selection \ No newline at end of file From fc13724a74b476883e2a61cee3a7296193c44c29 Mon Sep 17 00:00:00 2001 From: cdhiraj40 Date: Tue, 20 Sep 2022 07:02:26 +0530 Subject: [PATCH 2/7] Added training data for overall cancel command --- data/nlu/nlu.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/nlu/nlu.yml b/data/nlu/nlu.yml index dc785f4..6f8658d 100644 --- a/data/nlu/nlu.yml +++ b/data/nlu/nlu.yml @@ -175,6 +175,20 @@ nlu: - choose [second](car_selection_number) car - choose [third](car_selection_number) car please + - intent: overall_cancel_command + examples: | + - cancel + - cancel it + - cancel everything + - cancel all + - cancel start recording + - cancel stop recording + - cancel select car + - cancel choose car + - can you cancel this + - please cancel command + - enviroBot cancel this + - synonym: select examples: | - select From 2a9e4927a0ab73cae81b8789960210909cfee197 Mon Sep 17 00:00:00 2001 From: cdhiraj40 Date: Tue, 20 Sep 2022 07:04:03 +0530 Subject: [PATCH 3/7] Added results folder in .gitignore to avoid test results to be pushed --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7973050..5df3584 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ Pipfile.lock story_graph.dot endpoints.yml +results/ \ No newline at end of file From e093879bbd91765ed460ee581a3a7775afa96ea1 Mon Sep 17 00:00:00 2001 From: cdhiraj40 Date: Thu, 22 Sep 2022 18:55:17 +0530 Subject: [PATCH 4/7] Added rules for the overall cancel command --- data/rules.yml | 7 ++++++- domain.yml | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/data/rules.yml b/data/rules.yml index 5c77c2d..072de8a 100644 --- a/data/rules.yml +++ b/data/rules.yml @@ -62,4 +62,9 @@ rules: steps: - slot_was_set: - car_verification: yes - - action: action_car_selection \ No newline at end of file + - action: action_car_selection + + - rule: Run `cancel_commands` action whenever `overall_cancel_command` intent is triggered + steps: + - intent: overall_cancel_command + - action: action_cancel_commands \ No newline at end of file diff --git a/domain.yml b/domain.yml index 6bb1689..cc3268b 100644 --- a/domain.yml +++ b/domain.yml @@ -24,6 +24,7 @@ actions: - action_ask_car_verification - action_car_selection - action_followup + - action_cancel_commands forms: car_selection_form: @@ -88,7 +89,6 @@ slots: requested_slot: car_number car_name: type: text - influence_conversation: true mappings: - type: custom conditions: @@ -106,7 +106,6 @@ slots: requested_slot: select_car_iteration next_car: type: bool - influence_conversation: true mappings: - type: custom conditions: @@ -114,7 +113,6 @@ slots: requested_slot: next_car previous_car: type: bool - influence_conversation: true mappings: - type: custom conditions: From 4020f6c421f753a5e782319bfbe783f8c26c18c7 Mon Sep 17 00:00:00 2001 From: cdhiraj40 Date: Thu, 22 Sep 2022 18:55:50 +0530 Subject: [PATCH 5/7] Added cancel commands action --- actions/cancel_command_actions/__init__.py | 0 .../action_cancel_commands.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 actions/cancel_command_actions/__init__.py create mode 100644 actions/cancel_command_actions/action_cancel_commands.py diff --git a/actions/cancel_command_actions/__init__.py b/actions/cancel_command_actions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/actions/cancel_command_actions/action_cancel_commands.py b/actions/cancel_command_actions/action_cancel_commands.py new file mode 100644 index 0000000..77107a6 --- /dev/null +++ b/actions/cancel_command_actions/action_cancel_commands.py @@ -0,0 +1,19 @@ +from typing import Any, Text, Dict, List + +from rasa_sdk.events import AllSlotsReset, ActiveLoop +from rasa_sdk import Action, Tracker +from rasa_sdk.executor import CollectingDispatcher + + +class ActionCancelCommands(Action): + """This is the action that is called when the user says "cancel".""" + + @staticmethod + def name(**kwargs) -> Text: + return "action_cancel_commands" + + def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], **kwargs) -> List[ + Dict[Text, Any] + ]: + dispatcher.utter_message("Okay, cancelling running commands!") + return [AllSlotsReset(), ActiveLoop(None)] From f992d7494af280377e63953dae52bb998d1f80b0 Mon Sep 17 00:00:00 2001 From: Dhiraj Chauhan Date: Wed, 19 Jul 2023 15:25:20 +0530 Subject: [PATCH 6/7] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0c9c60a..1aaf6f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7.7-stretch AS BASE +FROM python:3.7.7-slim AS BASE RUN apt-get update \ && apt-get --assume-yes --no-install-recommends install \ From ea637fd034d58ccdca73d258a2909a64fec9a716 Mon Sep 17 00:00:00 2001 From: Dhiraj Chauhan Date: Wed, 19 Jul 2023 16:34:08 +0530 Subject: [PATCH 7/7] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 1aaf6f7..d4df404 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ WORKDIR /app RUN pip install --no-cache-dir --upgrade pip RUN pip install rasa==3.2.5 +RUN pip install websockets==10.0 ADD config.yml config.yml ADD domain.yml domain.yml