diff --git a/Rasa_Bot/README.md b/Rasa_Bot/README.md index 376165fa..3b97652a 100644 --- a/Rasa_Bot/README.md +++ b/Rasa_Bot/README.md @@ -17,7 +17,7 @@ The steps are as follows: - The output for the above command should be something like this: [{"recipient_id":"user","text":"Sure, you should ..."}] - See [this page](https://rasa.com/docs/rasa/connectors/your-own-website#restinput) for details on how to use the REST channel. -Note that while the requirements-file lists Rasa 3.1.0 as a requirement, this is only needed to train a language model and handy when developing. +Note that while the requirements-file lists Rasa 3.2.8 as a requirement, this is only needed to train a language model and handy when developing. NB: If you want to run rasa outside of docker, you might want to change the urls in `endpoints.yml`. @@ -27,7 +27,7 @@ in `endpoints.yml`. We no longer use spacy language embeddings, and we removed entity recognition from the pipeline. Let's keep an eye on whether we want to keep doing this. ### Rasa Version -Currently, the model is trained in Rasa 3.1.0. Different Rasa versions are not necessarily compatible w.r.t. e.g. layout of the language model files, so we should eventually choose a specific Rasa version, probably the most current one. See [here](https://rasa.com/docs/rasa/changelog) for the changelog for Rasa Open Source. +Currently, the model is trained in Rasa 3.2.8. Different Rasa versions are not necessarily compatible w.r.t. e.g. layout of the language model files, so we should eventually choose a specific Rasa version, probably the most current one. See [here](https://rasa.com/docs/rasa/changelog) for the changelog for Rasa Open Source. ### Agent Name The agent name is set in the "domain.yml"-file in the slot "agent_name." Changing this name in said file requires retraining the model. diff --git a/Rasa_Bot/actions/Dockerfile b/Rasa_Bot/actions/Dockerfile index 6a819808..e312495e 100644 --- a/Rasa_Bot/actions/Dockerfile +++ b/Rasa_Bot/actions/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile for rasa actions server # Pull SDK image as base image, version must be compatible with Rasa version -FROM rasa/rasa-sdk:3.1.1 +FROM rasa/rasa-sdk:3.2.1 # Use subdirectory as working directory WORKDIR /app diff --git a/Rasa_Bot/config.yml b/Rasa_Bot/config.yml index 43110004..1fc0f2a9 100644 --- a/Rasa_Bot/config.yml +++ b/Rasa_Bot/config.yml @@ -26,8 +26,8 @@ pipeline: - name: ResponseSelector epochs: 100 - name: FallbackClassifier - threshold: 0.4 - ambiguity_threshold: 0.1 + threshold: 0.3 # NB: threshold for low NLU confidence. Need to tune carefully. + # Configuration for Rasa Core. # https://rasa.com/docs/rasa/core/policies/ diff --git a/Rasa_Bot/data/nlu.yml b/Rasa_Bot/data/nlu.yml index 1c2808c3..d5d2a153 100644 --- a/Rasa_Bot/data/nlu.yml +++ b/Rasa_Bot/data/nlu.yml @@ -1,4 +1,4 @@ -version: "3.0" +version: "3.1" nlu: - intent: request_plan_week @@ -44,11 +44,17 @@ nlu: - "Ik wil future self dialog." - "future self dialog." -- intent: get_first_aid_kit +- intent: CENTRAL_get_first_aid_kit examples: | - "Get first aid kit" - "Ik wil first aid kit" - "First aid kit" + - "EHBO doos" + +- intent: urgent + examples: | + - "dood" + - "Ik ben depressief" - intent: request_tracked_cigarettes examples: | @@ -57,7 +63,7 @@ nlu: - intent: request_tracker_reminder examples: | - "Kun je een herinnering instellen om de gerookte sigaretten te tracken?" - + - intent: EXTERNAL_trigger_profile_creation examples: | - "EXTERNAL_trigger_profile_creation" diff --git a/Rasa_Bot/data/rules.yml b/Rasa_Bot/data/rules.yml index fa63cd80..8cd8f106 100644 --- a/Rasa_Bot/data/rules.yml +++ b/Rasa_Bot/data/rules.yml @@ -1,10 +1,21 @@ -version: "3.0" +version: "3.1" rules: -- rule: Ask the user to rephrase whenever they send a message with low NLU confidence +- rule: Give user central mode options when they send a message with low NLU confidence steps: - intent: nlu_fallback - action: utter_default + - action: utter_central_mode_options + - action: action_end_dialog + +# Only applies at start of conversation +- rule: Process when people talk about urgent things that we cannot handle + conversation_start: true + steps: + - intent: urgent + - action: utter_refer + - action: utter_central_mode_options + - action: action_end_dialog - rule: Ask for foreseen smoking HRS whenever this is externally triggered (by scheduler) steps: diff --git a/Rasa_Bot/data/stories_execution_dialogs.yml b/Rasa_Bot/data/stories_execution_dialogs.yml index b0853b71..e034f7a2 100644 --- a/Rasa_Bot/data/stories_execution_dialogs.yml +++ b/Rasa_Bot/data/stories_execution_dialogs.yml @@ -1,7 +1,7 @@ # Execution dialogs stories # Purpose: Placeholder for the stories to be triggered in the execution phase # Context: Execution phase -version: "3.0" +version: "3.1" stories: diff --git a/Rasa_Bot/data/stories_first_aid_kit.yml b/Rasa_Bot/data/stories_first_aid_kit.yml index 38e38fb5..e0e31c6d 100644 --- a/Rasa_Bot/data/stories_first_aid_kit.yml +++ b/Rasa_Bot/data/stories_first_aid_kit.yml @@ -1,11 +1,11 @@ # Stories related to the first aid kit functionality -version: "3.0" +version: "3.1" stories: ## Get first aid kit - kit exists - story: Get first aid kit exists steps: - - intent: get_first_aid_kit + - intent: CENTRAL_get_first_aid_kit - action: action_get_first_aid_kit - slot_was_set: - first_aid_kit_exists: true @@ -16,7 +16,7 @@ stories: ## Get first aid kit - kit does not exist yet - story: Get first aid kit does not exist steps: - - intent: get_first_aid_kit + - intent: CENTRAL_get_first_aid_kit - action: action_get_first_aid_kit - slot_was_set: - first_aid_kit_exists: false diff --git a/Rasa_Bot/data/stories_future_self_dialog.yml b/Rasa_Bot/data/stories_future_self_dialog.yml index e8aed6cd..9ca3ebd8 100644 --- a/Rasa_Bot/data/stories_future_self_dialog.yml +++ b/Rasa_Bot/data/stories_future_self_dialog.yml @@ -3,7 +3,7 @@ # Context: Preparation phase, one or two days (to be decided) # after deciding whether or not to use medication. # This activity is being repeated several times throughout the intervention. -version: "3.0" +version: "3.1" stories: - story: future-self dialog introduction diff --git a/Rasa_Bot/data/stories_minimum_functional_product.yml b/Rasa_Bot/data/stories_minimum_functional_product.yml index d73c2abe..c85e147f 100644 --- a/Rasa_Bot/data/stories_minimum_functional_product.yml +++ b/Rasa_Bot/data/stories_minimum_functional_product.yml @@ -1,5 +1,5 @@ # Stories for minimum function product -version: "3.0" +version: "3.1" stories: - story: request_plan_week_calendarYes diff --git a/Rasa_Bot/data/stories_preparation_dialogs.yml b/Rasa_Bot/data/stories_preparation_dialogs.yml index bedb1b5d..8b04002a 100644 --- a/Rasa_Bot/data/stories_preparation_dialogs.yml +++ b/Rasa_Bot/data/stories_preparation_dialogs.yml @@ -1,7 +1,7 @@ # Preparation dialogs stories # Purpose: Placeholder for the stories to be triggered in the preparation phase # Context: Preparation phase -version: "3.0" +version: "3.1" stories: diff --git a/Rasa_Bot/data/stories_rescheduling_dialog.yml b/Rasa_Bot/data/stories_rescheduling_dialog.yml index b7edf6c2..59f26a06 100644 --- a/Rasa_Bot/data/stories_rescheduling_dialog.yml +++ b/Rasa_Bot/data/stories_rescheduling_dialog.yml @@ -1,5 +1,5 @@ # Stories for rescheduling dialog -version: "3.0" +version: "3.1" stories: diff --git a/Rasa_Bot/domain/domain_common.yml b/Rasa_Bot/domain/domain_common.yml index a96201b0..698e37bb 100644 --- a/Rasa_Bot/domain/domain_common.yml +++ b/Rasa_Bot/domain/domain_common.yml @@ -1,3 +1,13 @@ +intents: + - urgent + actions: - action_end_dialog - mark_dialog_as_completed + - action_handle_urgent_intent + + +responses: + # To refer a user to a human + utter_refer: + - text: "Volgens mij heb je een probleem waar een mens je beter mee kan helpen. Ik raad je aan om contact op te nemen met iemand die je vertrouwt, zoals je huisarts." \ No newline at end of file diff --git a/Rasa_Bot/domain/domain_first_aid_kit.yml b/Rasa_Bot/domain/domain_first_aid_kit.yml index 4d708852..ded916e6 100644 --- a/Rasa_Bot/domain/domain_first_aid_kit.yml +++ b/Rasa_Bot/domain/domain_first_aid_kit.yml @@ -1,5 +1,5 @@ intents: - - get_first_aid_kit + - CENTRAL_get_first_aid_kit slots: ### First aid kit diff --git a/Rasa_Bot/domain/domain_generic.yml b/Rasa_Bot/domain/domain_generic.yml index 2c782607..3b8fcfbe 100644 --- a/Rasa_Bot/domain/domain_generic.yml +++ b/Rasa_Bot/domain/domain_generic.yml @@ -29,9 +29,14 @@ slots: - type: custom responses: - # Fallback + # Fallback for low NLU confidence and low next action confidence + # For low next action confidence, "utter_default" is automatically called. + # For low NLU confidence, we have defined a rule. utter_default: - text: "Sorry, ik begrijp (nog) niet wat je bedoelt, kun je me het op een andere manier duidelijk maken?" + # We present the user with the options from the central mode + utter_central_mode_options: + - text: "Je kunt deze woorden gebruiken om met mij te praten: 1) EHBO doos, 2) ..., ... ." ### Re-prompts in forms utter_please_answer_1_2_3: diff --git a/Rasa_Bot/models/20220718-170310-angry-plywood.tar.gz b/Rasa_Bot/models/20220919-135636-either-croissant.tar.gz similarity index 68% rename from Rasa_Bot/models/20220718-170310-angry-plywood.tar.gz rename to Rasa_Bot/models/20220919-135636-either-croissant.tar.gz index 5ad8379a..4db08e22 100644 Binary files a/Rasa_Bot/models/20220718-170310-angry-plywood.tar.gz and b/Rasa_Bot/models/20220919-135636-either-croissant.tar.gz differ diff --git a/Rasa_Bot/requirements.txt b/Rasa_Bot/requirements.txt index 39676561..23eb2230 100644 --- a/Rasa_Bot/requirements.txt +++ b/Rasa_Bot/requirements.txt @@ -1,5 +1,6 @@ git+https://github.com/PerfectFit-project/niceday_client protobuf==3.20.1 # temporary fix -rasa==3.1.0 # NB! when updating, make sure to also update: +rasa==3.2.8 # NB! when updating, make sure to also update: # * rasa base image in actions/Dockerfile, + # * version number in nlu.yml, story files, rules.yml, # * format of stories, domain.yml etc. if necessary diff --git a/scheduler/celery_tasks.py b/scheduler/celery_tasks.py index 1aef3e4e..abf49022 100644 --- a/scheduler/celery_tasks.py +++ b/scheduler/celery_tasks.py @@ -51,7 +51,7 @@ def intervention_component_completed(user_id: int, intervention_component_name: headers = {'Content-Type': 'application/json'} params = {'output_channel': 'niceday_input_channel'} data = '{"name": "' + next_intervention_component + '" }' - requests.post(endpoint, headers=headers, params=params, data=data) + requests.post(endpoint, headers=headers, params=params, data=data, timeout=60) else: logging.info("PREPARATION PHASE ENDED") @@ -115,7 +115,7 @@ def trigger_intervention_component(self, user_id, trigger): # pylint: disable=u headers = {'Content-Type': 'application/json'} params = {'output_channel': 'niceday_input_channel'} data = '{"name": "' + trigger + '" }' - requests.post(endpoint, headers=headers, params=params, data=data) + requests.post(endpoint, headers=headers, params=params, data=data, timeout=60) def plan_execution_dialogs(user_id: int): diff --git a/virtual-coach-server/cms/managed_content_reader.py b/virtual-coach-server/cms/managed_content_reader.py index 2bdb0319..86728584 100644 --- a/virtual-coach-server/cms/managed_content_reader.py +++ b/virtual-coach-server/cms/managed_content_reader.py @@ -14,7 +14,7 @@ class ManagedContentReader: """ def __init__(self): - r = requests.get(MANAGED_CONTENT_URL) + r = requests.get(MANAGED_CONTENT_URL, timeout=60) if r.status_code != 200: logging.error( f'Failed to fetch from URL: {MANAGED_CONTENT_URL} '