Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart dialogs #85

Merged
merged 23 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
317815c
action to save part 1 goal-setting dialog
nelealbers Apr 14, 2023
ece5b69
add part saving to rule goal-setting
nelealbers Apr 14, 2023
e7f9bb2
change start of dialog based on previously completed part + get which…
nelealbers May 1, 2023
230c2d7
store which_sport slot to db when saving part 2
nelealbers May 1, 2023
a800b4d
which_sport now part of users table in db
nelealbers May 2, 2023
126a35b
add more explanations
nelealbers May 2, 2023
48a93e6
add logic for typing 'verder'
nelealbers May 2, 2023
09286e7
Merge branch 'main' into restart_dialogs
nelealbers May 2, 2023
92544d4
retrained after merge
nelealbers May 2, 2023
ff91adf
add celery.send_task to idle command actions for verder
nelealbers May 2, 2023
c15fcad
clean up
nelealbers May 3, 2023
93183e7
also need to set completed=False when storing dialog parts in db
nelealbers May 3, 2023
65f81e2
use new db release in actions requirements
nelealbers May 4, 2023
9796c03
db version also for scheduler and onboarding
nelealbers May 4, 2023
e835ac8
prospector complaints
nelealbers May 8, 2023
b85e1ad
Merge branch 'main' into restart_dialogs
nelealbers May 15, 2023
faa1f4b
correct menu selection and dialog restart from fsm
wbaccinelli May 17, 2023
5ff42c7
prospector corrections
wbaccinelli May 17, 2023
7b3a032
new db version
wbaccinelli May 17, 2023
222f5f9
Update Rasa_Bot/actions/helper.py
nelealbers May 17, 2023
27116ee
remove consideration of last_part = 0
nelealbers May 17, 2023
e4f7d95
remove old models
nelealbers May 17, 2023
4228019
remove last_part 0 also from rules goal-setting and retrain
nelealbers May 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 110 additions & 5 deletions Rasa_Bot/actions/actions_goal_setting_dialog.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""
Contains custom actions related to the relapse dialogs
"""
from virtual_coach_db.dbschema.models import (Testimonials, Users)
from virtual_coach_db.helper import (Components)
from virtual_coach_db.dbschema.models import (Testimonials,
Users)
from virtual_coach_db.helper.definitions import Components
from virtual_coach_db.helper.helper_functions import get_db_session
from . import validator
from .definitions import DATABASE_URL, TIMEZONE, FILE_PATH_IMAGE_PA
from .helper import (get_latest_bot_utterance, store_quit_date_to_db, store_long_term_pa_goal_to_db)
from .definitions import DATABASE_URL, FILE_PATH_IMAGE_PA, TIMEZONE
from .helper import (get_goal_setting_chosen_sport_from_db,
get_intervention_component_id,
get_last_completed_dialog_part_from_db,
get_latest_bot_utterance,
store_dialog_part_to_db,
store_goal_setting_chosen_sport_to_db,
store_long_term_pa_goal_to_db,
store_quit_date_to_db)
from datetime import datetime, timedelta
from rasa_sdk import Action, Tracker
from rasa_sdk.events import FollowupAction, SlotSet
Expand All @@ -15,6 +23,73 @@
from typing import Any, Dict, Text


class ActionSaveGoalSettingDialogPart1(Action):
"""To save first part of goal-setting dialog"""

def name(self):
return "action_save_goal_setting_dialog_part1"

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

store_dialog_part_to_db(tracker.current_state()['sender_id'],
get_intervention_component_id(Components.GOAL_SETTING),
part = 1)

return []


class ActionSaveGoalSettingDialogPart2(Action):
"""To save second part of goal-setting dialog"""

def name(self):
return "action_save_goal_setting_dialog_part2"

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

user_id = tracker.current_state()['sender_id']

store_dialog_part_to_db(user_id,
get_intervention_component_id(Components.GOAL_SETTING),
part = 2)

# Also need to store the "which_sport"-slot to the database
store_goal_setting_chosen_sport_to_db(user_id,
tracker.get_slot('which_sport'))

return []


class ActionSaveGoalSettingDialogPart3(Action):
"""To save third part of goal-setting dialog"""

def name(self):
return "action_save_goal_setting_dialog_part3"

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

store_dialog_part_to_db(tracker.current_state()['sender_id'],
get_intervention_component_id(Components.GOAL_SETTING),
part = 3)

return []


class ActionSaveGoalSettingDialogPart4(Action):
"""To save 4th part of goal-setting dialog"""

def name(self):
return "action_save_goal_setting_dialog_part4"

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

# 0 means that the entire dialog is completed
store_dialog_part_to_db(tracker.current_state()['sender_id'],
get_intervention_component_id(Components.GOAL_SETTING),
part = 0)

return []


class ActionGetFirstLastDate(Action):
def name(self):
return "action_get_first_last_date"
Expand Down Expand Up @@ -222,6 +297,36 @@ async def run(self, dispatcher, tracker, domain):

return [SlotSet('current_intervention_component',
Components.GOAL_SETTING)]


class ActionGetLastCompletedGoalSettingPart(Action):
def name(self):
return "action_get_last_completed_goal_setting_part"

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

user_id = tracker.current_state()['sender_id']
comp_id = get_intervention_component_id(Components.GOAL_SETTING)

# Return value can be -1, 1, 2, or 3.
last_part = get_last_completed_dialog_part_from_db(user_id,
comp_id)

# Need to set which_sport_continue_dialog slot in case last completed
# part was 2 or 3.
# This is because {which_sport} is included in utterances.
# Since the which_sport-slot is set as part of a form, we created
# an alternative slot, which_sport_continue_dialog, that is used in
# the utterances where needed using conditional response variations.
if last_part in {2, 3}:
which_sport = get_goal_setting_chosen_sport_from_db(user_id)

return [SlotSet('last_completed_goal_setting_dialog_part',
last_part),
SlotSet('which_sport_continue_dialog', which_sport)]

return [SlotSet('last_completed_goal_setting_dialog_part',
last_part)]


class ValidateWhichSportForm(FormValidationAction):
Expand Down Expand Up @@ -475,7 +580,7 @@ def name(self):

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

return [FollowupAction('utter_step_goal_pa_1')]
return [FollowupAction('action_save_goal_setting_dialog_part3')]


class ValidateFinishedWritingPaForm(FormValidationAction):
Expand Down
35 changes: 35 additions & 0 deletions Rasa_Bot/actions/actions_idle_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from celery import Celery
from rasa_sdk import Action
from .helper import dialog_to_be_completed
from virtual_coach_db.helper.definitions import Components
from .definitions import REDIS_URL

Expand Down Expand Up @@ -65,3 +66,37 @@ async def run(self, dispatcher, tracker, domain):
user_id = tracker.current_state()['sender_id']

celery.send_task('celery_tasks.user_trigger_dialog', (user_id, Components.MEDICATION_TALK))


class ActionSelectMenu(Action):
"""Determines which list of commands has to be used"""

def name(self):
return "action_select_menu"

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

user_id = tracker.current_state()['sender_id']

if dialog_to_be_completed(user_id):
dispatcher.utter_message(response="utter_central_mode_options")
else:
dispatcher.utter_message(response="utter_central_mode_options_without_verder")


class ActionTriggerUncompletedDialog(Action):
"""Trigger uncompleted dialog if there is one"""

def name(self):
return "action_trigger_uncompleted_dialog"

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

user_id = tracker.current_state()['sender_id']

if dialog_to_be_completed(user_id):
celery.send_task('celery_tasks.user_trigger_dialog',
(user_id, Components.CONTINUE_UNCOMPLETED_DIALOG))
else:
dispatcher.utter_message(response="utter_no_valid_uncompleted_dialog")
dispatcher.utter_message(response="utter_central_mode_options_without_verder")
12 changes: 6 additions & 6 deletions Rasa_Bot/actions/actions_set_video_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# set video links
class SetFakLink(Action):
""" set the link to the medication video"""
""" set the link to the first aid kit video"""

def name(self):
return "action_set_fak_video_link"
Expand All @@ -16,7 +16,7 @@ async def run(self, dispatcher, tracker, domain):


class SetFSLongVideoLink(Action):
""" set the link to the medication video"""
""" set the link to the long future self video"""

def name(self):
return "action_set_future_self_long_video_link"
Expand All @@ -27,7 +27,7 @@ async def run(self, dispatcher, tracker, domain):


class SetFSShortVideoLink(Action):
""" set the link to the medication video"""
""" set the link to the short future self video"""

def name(self):
return "action_set_future_self_short_video_link"
Expand All @@ -38,7 +38,7 @@ async def run(self, dispatcher, tracker, domain):


class SetExecutionIntroductionVideoLink(Action):
""" set the link to the medication video"""
""" set the link to the execution introduction video"""

def name(self):
return "action_set_execution_introduction_video_link"
Expand All @@ -49,7 +49,7 @@ async def run(self, dispatcher, tracker, domain):


class SetPreparationIntroductionVideoLink(Action):
""" set the link to the medication video"""
""" set the link to the preparation introduction video"""

def name(self):
return "action_set_preparation_introduction_video_link"
Expand All @@ -71,7 +71,7 @@ async def run(self, dispatcher, tracker, domain):


class SetTrackBehaviorVideoLink(Action):
""" set the link to the medication video"""
""" set the link to the track behavior video"""

def name(self):
return "action_set_track_behavior_video_link"
Expand Down
Loading