Version:
- rasa 1.2.3
- rasa-sdk 1.2.0
Problem:
When running my bot the form authenticate_form_short
is not triggered. it seems like the bot doesn’t know that it is time to start the form. I used to use the old RASA version 0.0.X. Recently I upgrated RASA to 1.2.3. To do this, I started a complete new RASA project with a different folder structure (see figure below). Since that day, my bot doesnt work anymore. The code is mostly the same as in the previous project. All I did was changing some details according to migration guide 1 and migration guide 2.
→ Both are obviously NOT complete
I have a very short story called story_testing
. Every utter
in this story (see below) works as excpected. Once the form is supposed to start, nothing happends! The utter is not triggered. That means, the form doesn’t ask the user to write his name. Instead there is simply a blank line in my frontend. If I write my name MyName
, I get the following error message in my terminal 2:
Failed to validate slot name with action authenticate_form_short
Possible Solution A: → most likely !!!
I think the way I start the bot is not correct. Or is it?
Terminal 1:
rasa run --endpoints endpoints.yml --credentials credentials.yml
Terminal 2:
rasa run actions --actions actions
Terminal 3 (in folder frontend):
livereload
Here is my directory tree:
Possible Solution B:
There is a problem with my frontend. However,I think this is not the case! I tried to start the bot only in my terminal. After doing rasa train
, I write rasa shell
. Afterwards the bot starts. Once the form should be triggered (according my story story_testing
) it says:
rasa.core.actions.action - Failed to run custom action ‘authenticate_form_short’. Couldn’t connect to the server at ‘http://localhost:5055/webhook’. Is the server running? Error: Cannot connect to host loc alhost:5055 ssl:None [Connect call failed (‘::1’, 5055, 0, 0)]
rasa.core.processor - Encountered an exception while running action ‘authenticate_form_short’. Bot will continue, but the actions events are lost. Please check the logs of your action server for more infor mation.
Possible Solution C:
the action.py file is not in correct folder. Therefore I copied it in 2 folders. You can find it in the action-folder as well in rasa_project folder. I could find both ways on the internet
Possible Solution D:
Maybe my policies are not correct.
config.yml
language: "de_core_news_sm"
pipeline: pretrained_embeddings_spacy
policies:
- name: "KerasPolicy"
epochs: 400
max_history: 3
- name: "MemoizationPolicy"
max_history: 3
- name: "FormPolicy" # To use forms, you also need to include the FormPolicy in your policy configuration file.
- name: "FallbackPolicy"
# min confidence needed to accept an NLU prediction
nlu_threshold: 0.3
# min confidence needed to accept an action prediction from Rasa Core
core_threshold: 0.3
# name of the action to be called if the confidence of intent / action
# is below the threshold
fallback_action_name: 'action_default_fallback'
Last but not least, here are some relevant files:
stories.md
## story_testing
* greet
- utter_introduction
* pleaseWait
- utter_alright
* bye
- utter_bye_servicetime
- authenticate_form_short
- form{"name": "authenticate_form_short"}
- slot{"name": "Sam"}
- slot{"name_last": "Johns"}
- slot{"contract_no": "123457890"}
- form{"name": null}
actions.py
from datetime import datetime
import datetime as dt
import re
import os
from typing import Dict, Text, Any, List, Union
from dateutil.relativedelta import relativedelta
from rasa_sdk import ActionExecutionRejection, Tracker, Action
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction, REQUESTED_SLOT
from rasa.nlu.utils import write_json_to_file
from rasa.core.policies.fallback import FallbackPolicy
from rasa.core.agent import Agent
from rasa.core.policies.keras_policy import KerasPolicy
from rasa.core.policies.form_policy import FormPolicy, MemoizationPolicy
class AuthenticateFormShort(FormAction):
"""Short authentication for other questions."""
def name(self):
# type: () -> Text
"""Unique identifier of the form"""
return "authenticate_form_short"
@staticmethod
def required_slots(tracker):
# type: () -> List[Text]
"""A list of required slots that the form has to fill"""
return ["name", "name_last",
"contract_no"] # Every time the form action gets called, it will ask the user for the next slot in required_slots which is not already set. Note the order!!!
def submit(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict]
"""Define what the form has to do
after all required slots are filled"""
# utter submit template
dispatcher.utter_template('utter_form_bye', tracker)
return []
def slot_mappings(self):
# type: () -> Dict[Text: Union[Dict, List[Dict]]]
"""A dictionary to map required slots to
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
return {
"name": [self.from_entity(entity="name", not_intent=["chitchat"])],
"name_last": [self.from_entity(entity="name_last", not_intent=["chitchat"])],
"contract_no": [self.from_entity(entity="contract_no", not_intent=["chitchat"])],
}
def validate(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict]:
"""Validate extracted requested slot
else reject the execution of the form action
"""
# extract other slots that were not requested
# but set by corresponding entity
slot_values = self.extract_other_slots(dispatcher, tracker, domain)
# extract requested slot
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
if slot_to_fill:
slot_values.update(self.extract_requested_slot(dispatcher,
tracker, domain))
if not slot_values:
# reject form action execution
# if some slot was requested but nothing was extracted
# it will allow other policies to predict another action
raise ActionExecutionRejection(self.name(),
"Failed to validate slot {0} "
"with action {1}"
"".format(slot_to_fill,
self.name()))
# we'll check when validation failed in order
# to add appropriate utterances
for slot, value in slot_values.items():
*.....The following is only the validation process....*
# validation succeed, set the slots values to the extracted values
return [SlotSet(slot, value) for slot, value in slot_values.items()]
Can you please help me to trigger my form, please!