I created a new Action, which gets executed at starting of session.
That action, sends welcome message by BOT, and then loads embeddings.
But, i am observing that welcome message is coming later , after embeddings has been loaded, which is giving delay of 4-5secs
Can anyone help me out, how to remove that delay or make sure welcome message is send asap as session starts, and in mean time user types, embedding will get loaded.
NOTE: Welcome msg comes after " Finished running ‘action_session_start’" in logs
CODE:
class ActionSessionStart(Action):
def __init__(self):
ActionSessionStart.em = None
def name(self) -> Text:
return "action_session_start"
def run(
self,
dispatcher: CollectingDispatcher,
tracker,
domain: Dict[Text, Any],) :
"""This run function will be executed when "action_session_start" is triggered."""
dispatcher.utter_message("Hellooo! Genie welcomes you ")
print("action_session_start")
em = embedding_model_DnA()
em.load_embeddings()
LOGS:
2021-12-11 09:32:23 DEBUG rasa_sdk.executor - Received request to run 'action_session_start'
action_session_start
load_embeddings
2021-12-11 09:32:29 INFO sentence_transformers.SentenceTransformer - Load pretrained SentenceTransformer
2021-12-11 09:32:32 INFO sentence_transformers.SentenceTransformer - Use pytorch device: cpu
2021-12-11 09:32:32 DEBUG rasa_sdk.executor - Finished running 'action_session_start'
@Eshita The message will be uttered after the whole function finished running.
With @RodrigoLima’s method, action will first wait 2.4 seconds and then utter the two messages at the same time - don’t do that. Also Rodrigo, I think Eshita wants to remove the delay, not add one.
What you can do is use FollowupAction to load embeddings in a second action.
@ChrisRahme : thanks for your response… this is actually what i was looking for.
Also,I updated the code as u suggested, added action in domain.yml too…
But FollowupAction “action_load_embeddings” is not executing.
Print statement not getting printed, embeddings not getting loaded.
Also no error.
Can u please suggest what i be doing wrong:
ACTIONS:
from rasa_sdk.events import FollowupAction
class ActionSessionStart(Action):
def name(self) -> Text:
return "action_session_start"
def run(
self,
dispatcher: CollectingDispatcher,
tracker,
domain: Dict[Text, Any],) :
"""This run function will be executed when "action_session_start" is triggered."""
dispatcher.utter_message("Hellooo! Genie welcomes you")
print("action_session_start")
return [FollowupAction('action_load_embeddings')]
class ActionLoadEmbeddings(Action):
""" Loads embeddings after session starts"""
def __init__(self):
ActionLoadEmbeddings.em = None
def name(self) -> Text:
return 'action_load_embeddings'
def run(self, dispatcher, tracker, domain):
print(" In ActionLoadEmbeddings")
em = embedding_model_DnA()
em.load_embeddings()
ActionLoadEmbeddings.em = em
return []
OUTPUT:
2021-12-12 23:27:47 INFO rasa_sdk.endpoint - Starting action endpoint server...
2021-12-12 23:27:55 INFO rasa_sdk.executor - Registered function for 'action_faq'.
2021-12-12 23:27:55 INFO rasa_sdk.executor - Registered function for 'action_fetch_button_value'.
2021-12-12 23:27:55 INFO rasa_sdk.executor - Registered function for 'action_open_link'.
2021-12-12 23:27:55 INFO rasa_sdk.executor - Registered function for 'action_session_start'.
2021-12-12 23:27:55 INFO rasa_sdk.executor - Registered function for 'action_load_embeddings'.
2021-12-12 23:27:55 INFO rasa_sdk.endpoint - Action endpoint is up and running on http://0.0.0.0:5055
action_session_start
test input ---- > > > machine learning
Expected"
Before test input, " In ActionLoadEmbeddings" must be printed
I suggest starting a new thread called “FollowupAction for ActionSessionStart”, since it’s now kind of a different problem and it will get new viewers, and send the link to that thread here in case future readers want to follow it.
I don’t know what content you are loading but why don’t you try a function in python that waits for the content to load before going to the next function?
type a for while