from typing import Any, Text, Dict, List, Union
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
class ActionHelloWorld(Action):
def name(self) -> Text:
return "action_hello_world"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
dispatcher.utter_message("Hello World!")
return []
class BalanceForm(FormAction):
def name(self):
return "balance_form"
@staticmethod
def required_slots(tracker) -> List[Text]:
return["card_number"]
def submit(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
dispatcher.utter_message("It's working!!!")
return []
For the above python script, dispatcher.utter_message works for action_hello_world but not for FormAction in rasa shell. Very confused about why this is happening.
siriusraja
(Raja Duraisingam)
November 29, 2020, 9:50am
3
Hi @ria.pinjani
What does your debug log says ?
Is the form action gets predicted as next action?
Your input -> check balance for 4000002485703167
2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Issuing ticket for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Acquiring lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
2020-11-29 15:15:42 DEBUG rasa.core.lock_store - Acquired lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
2020-11-29 15:15:42 DEBUG rasa.core.tracker_store - Creating a new tracker for id ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
2020-11-29 15:15:42 DEBUG rasa.core.processor - Starting a new session for conversation ID ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
2020-11-29 15:15:42 DEBUG rasa.core.processor - Action ‘action_session_start’ ended with events ‘[<rasa.shared.core.events.SessionStarted object at 0x7ff8bb074518>, <rasa.shared.core.events.ActionExecuted object at 0x7ff8bb0744e0>]’.
2020-11-29 15:15:42 DEBUG rasa.core.processor - Current slot values:
amount_of_money: None
card_number: None
currency: None
person: None
requested_slot: None
2020-11-29 15:15:43 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: faq
2020-11-29 15:15:43 DEBUG rasa.nlu.selectors.response_selector - Adding following selector key to message property: chitchat
2020-11-29 15:15:43 DEBUG rasa.core.processor - Received user message ‘check balance for 4000002485703167’ with intent ‘{‘id’: -164258592526541612, ‘name’: ‘check_balance’, ‘confidence’: 0.9976837635040283}’ and entities ‘[{‘entity’: ‘card_number’, ‘start’: 18, ‘end’: 34, ‘confidence_entity’: 0.7931957840919495, ‘value’: ‘4000002485703167’, ‘extractor’: ‘DIETClassifier’}]’
2020-11-29 15:15:43 DEBUG rasa.core.processor - Current slot values:
amount_of_money: None
card_number: 4000002485703167
currency: None
person: None
requested_slot: None
2020-11-29 15:15:43 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 5 events.
2020-11-29 15:15:43 DEBUG rasa.core.policies.rule_policy - Current tracker state: [{}, {‘user’: {‘intent’: ‘check_balance’, ‘entities’: (‘card_number’,)}, ‘prev_action’: {‘action_name’: ‘action_listen’}}]
2020-11-29 15:15:43 DEBUG rasa.core.policies.rule_policy - There is no applicable rule.
2020-11-29 15:15:43 DEBUG rasa.core.policies.memoization - Current tracker state [{}, {‘user’: {‘intent’: ‘check_balance’, ‘entities’: (‘card_number’,)}, ‘prev_action’: {‘action_name’: ‘action_listen’}}]
2020-11-29 15:15:43 DEBUG rasa.core.policies.memoization - There is no memorised next action
2020-11-29 15:15:43 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_RulePolicy
2020-11-29 15:15:43 DEBUG rasa.core.processor - Predicted next action ‘action_default_fallback’ with confidence 0.30.
2020-11-29 15:15:43 DEBUG rasa.core.processor - Action ‘action_default_fallback’ ended with events ‘[<rasa.shared.core.events.UserUtteranceReverted object at 0x7ff8bac9b160>]’.
2020-11-29 15:15:43 DEBUG rasa.core.processor - Current slot values:
amount_of_money: None
card_number: None
currency: None
person: None
requested_slot: None
2020-11-29 15:15:43 DEBUG rasa.core.processor - Predicted next action ‘action_listen’ with confidence 1.00.
2020-11-29 15:15:43 DEBUG rasa.core.processor - Action ‘action_listen’ ended with events ‘[]’.
2020-11-29 15:15:43 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘6d722e5664ee4dc0a4be0ffbf28967c9’.
Your input ->
No it’s not i believe.
This is my stories.md file;
greet
happy path
sad path 1
greet
mood_unhappy
utter_cheer_up
utter_did_that_help
affirm
sad path 2
greet
mood_unhappy
utter_cheer_up
utter_did_that_help
deny
say goodbye
bot challenge
check balance
check_balance
balance_form
form{“name” : “balance_form”}
form{“name” : null}
affirm
greet & check balance
greet
check_balance
balance_form
form{“name” : “balance_form”}
form{“name” : null}
check balance continue
greet
check_balance
balance_form
form{“name”: “balance_form”}
out_of_scope
affirm
balance_form
form{“name”: null}
check balance stop
greet
check_balance
balance_form
form{“name”: “balance_form”}
out_of_scope
deny
action_deactivate_form
form{“name”: null}
utter_goodbye
transfer money
transfer_money
transfer_form
form{“name” : “transfer_form”}
form{“name” : null}
utter_transfer_completed
affirm
greet, check balance and transfer money
greet
check_balance
balance_form
form{“name” : “balance_form”}
form{“name” : null}
transfer_money
transfer_form
form{“name” : “transfer_form”}
form{“name” : null}
utter_transfer_completed
affirm
hello world
siriusraja
(Raja Duraisingam)
November 29, 2020, 12:05pm
7
Hi @ria.pinjani
I could not see your form action getting predicted.
Your stories also looks fine.
Have you included form action policy in your config ?
I could see you haven’t intended return statement line for static method in action.py. Doesn’t it throw error?
Yeah i fixed the indentation so thats not the issue.
I used the RulePolicy is my config file as mentioned here (end of page) - Policies
siriusraja
(Raja Duraisingam)
November 29, 2020, 12:17pm
9
The docs you referred are for version 2.x
Which rasa version are you using ?
ria.pinjani
(Ria Pinjani)
November 29, 2020, 12:19pm
10
Rasa Version : 2.0.2
Rasa SDK Version : 2.1.1
Rasa X Version : 0.33.2
Python Version : 3.6.10
siriusraja
(Raja Duraisingam)
November 29, 2020, 1:35pm
11
Since your version is 2.x, Can you update the stories to latest format as in yaml
Also share your domain file content
siriusraja
(Raja Duraisingam)
November 30, 2020, 7:34am
14
Hi @ria.pinjani
Domain.yml
looks good.
Did you got chance to upgrade your stories to latest format stories.yml
I did - it still does not work.
siriusraja
(Raja Duraisingam)
November 30, 2020, 10:33am
17
Hi @ria.pinjani ,
I just noticed another error in your actions.py
Since your version is 2.x, Please make the below changes as well in your form action class.
class BalanceForm(FormAction):
to class BalanceForm(Action):
def submit
to def run
your stories looks good. Retrain your model & make the above updates to your actions file.
Let me know if it works.
ria.pinjani
(Ria Pinjani)
November 30, 2020, 11:15am
18
It still does not seem to predict balance form in rasa shell. I don’t understand whats happening.
ria.pinjani
(Ria Pinjani)
November 30, 2020, 11:22am
19
This is the updated project if it helps - GitHub - riapinjani/rasa_demo
Thanks for all your help!!
siriusraja
(Raja Duraisingam)
December 4, 2020, 5:35pm
20
Hi @ria.pinjani
I have fixed the code and its available here GitHub - rajaduraisingam/rasa_demo
Main issue is demo bot was developed in 1.x version but you have been trying that in 2.x . There were lot of changes happened since 1.x and hence it was throwing errors.
Have a look at the files to understand the flow.
In the above screenshot, if you enter the card number it will execute the action successfully.
However, if we don’t specify the card number, it will ask the card number. After providing the card number, it says Bye which requires small fix which you can take it forward.
1 Like