Rasa 3.0 Custom actions not working

Hi all,

I am newbie to Rasa, I am trying to develop a chatbot which translates text when prompted. Example: Bot–> What can I translate for you today? User–> translate good in spanish Bot–> Translated sentence: buen

I am unable to get a response from the bot, it is only taking input when I type.

I am attaching the screenshot of the problem, actions, domain and nlu file. domain.yml (1.1 KB)

Any help would be great! Thanks Yashi

actions.py (1.5 KB) nlu.yml (2 KB)

Hello Yashi and welcome to the forum!

@yashi please share the rasa --version.

@yashi can you share stories or rule.yml file also? and even share the action server error log ?

@yashi is your action server is running in the second terminal? rasa run actions --debug

Please run rasa shell --debug to get more info on what is happening.

I suggest using rasa interactive as well to let your bot add data (intents, entities, stories) in case you missed any. This looks to me like you just may not have written a story.

Hi @nik202 , thanks
this the rasa version:

(rasa_new) D:>rasa --version Rasa Version : 3.0.5 Minimum Compatible Version: 3.0.0 Rasa SDK Version : 3.0.3 Rasa X Version : None Python Version : 3.8.9 Operating System : Windows-10-10.0.19041-SP0 Python Path : d:\rasa_new\scripts\python.exe

Yes my action server is running in 2nd terminal I have run rasa shell --debug and rasa run actions --debug , I have attached files,. Please let me know if I am missing something. rules.yml (343 Bytes) stories.yml (782 Bytes) rasa run actions --debug.txt (1.2 KB) rasa shell --debug.txt (10.9 KB)

Hi @ChrisRahme, thanks for your suggestion I have written a story, refer to the file attached.

I also run rasa shell --debug and got this output for my input to the bot. I have attached the output also.

and Do I need to explicitly install rasa interactive? using pip install? or it gets automatically installed with pip install rasa, because I ran the command rasa --version and for Rasa X it is showing none as version. Please let me know if I am missing something. rasa shell --debug.txt (10.9 KB)

(rasa_new) D:>rasa --version 
Rasa Version : 3.0.5 
Minimum Compatible Version: 3.0.0 
Rasa SDK Version : 3.0.3 
Rasa X Version : None 
Python Version : 3.8.9 
Operating System : Windows-10-10.0.19041-SP0 Python Path : d:\rasa_new\scripts\python.exe

rules.yml (343 Bytes) stories.yml (782 Bytes)

A line of your debug says you have no rules for that intent:

2022-01-25 11:34:38 DEBUG    rasa.core.policies.rule_policy  - There is no applicable rule.

And indeed, seeing your rules.yml file, there is none. So I went to check your stories.yml, and there is this one story:

- story: translating 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: translate
    entities:
    - sentence: good morning
    - to_lang: spanish
  - action: action_translate_to_lang

This story will only happen after the user greeted then asked for translation with sentence entity being exactly good morning and to_lang entity being exactly spanish.

Furthermore, stories as not as powerful as rules. Best practice would be creating a rule as a direct intent-to-action link first and foremost, like so

- rule: translating
  steps:
  - intent: translate
  - action: action_translate_to_lang

and then you can reinforce/encourage/discourage the behavior using stories.


No, you don’t have to do anything else


That’s because you haven’t installed Rasa X, a graphical interface for Rasa. I highly encourage doing do but it is not required.

Hi @ChrisRahme , Actually I had written a rule in rules.yml file

- rule: translate to language
  steps:
  - intent: translate
  - action: action_translate_to_lang

is this not the correct way to write the rule? I have tried to create the story I had written in stories.yml file

- story: translating 1
  steps:
  - intent: greet
  - action: utter_greet
  - intent: translate
    entities:
    - sentence: good morning
    - to_lang: spanish
  - action: action_translate_to_lang

Still I am not getting any response from the bot. Also I had re-run rasa shell --debug using the rule you suggested, and tried to re-create the story again. Attaching the debug logs. rasa shell --debug_01.txt (27.1 KB) I am seeing this line in the debug 2022-01-25 15:15:01 DEBUG rasa.core.policies.rule_policy - There is a rule for the next action 'action_listen'. is this the root cause for this issue? if so then how can I resolve it? And could you please suggest a more generalized story for this translator bot. Thanks Yashi

@yashi share the config.yml ?

Hi @nik202 , attaching the file. config.yml (1.6 KB)

Maybe a very stupid question, but did you train the bot after each change?

@yashi

pipeline.
# See https://rasa.com/docs/rasa/tuning-your-model for more information.
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
    constrain_similarities: true
  - name: EntitySynonymMapper
  - name: FallbackClassifier
    threshold: 0.3
    ambiguity_threshold: 0.1
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
  - name: MemoizationPolicy
  - name: RulePolicy
  - name: UnexpecTEDIntentPolicy
    max_history: 5
    epochs: 100
  - name: TEDPolicy
    max_history: 5
    epochs: 100
    constrain_similarities: true

This is default pipeline of Rasa 3.X

Observation: You are using custom pipeline ? You are using RegexEntityExtractor Any specific reason? Just trying to understand your use-case. Or If you can share the link from where you get this idea? Thanks.

Hi @ChrisRahme Yes I have trained the bot after every change.

Hi @nik202 Actually I was following this tutorial.

@yashi ok then pipeline make sense to me. Do you also have translate.py file?

@yashi can you even delete all the older trained models and trained it again and check?

Hi @nik202 No I dont have translate.py file, I have written the translation code in the actions.py itself.

Are you asking if I had tested the python code before adding it in the actions.py file?

And I trained the model again after deleting the old trained models, it is still giving the same result. rasa shell --debug_02.txt (72.0 KB)

@yashi then how do you translate from English to Spanish? Am I’m missing something?

In actions.py you are using

from translate import Translator

translation=translator.translate(sentence)

you are using the translate function for translation.

If you are using some translate reference code please share it with us?

@nik202 , Actually translate is an inbuilt python library which I am using.

Is it not the correct way to use python libraries in rasa?

I made this python code for testing the translate library functionality.

main.py (252 Bytes)

@yashi If you have main.py then you need to use

from main import Translator

Ref: Python - Call function from another file - GeeksforGeeks

Tip: Try use print() in every output, so that you get it in rasa run actions --debug

I hope now you able to solve?

@nik202 no no, I dont have a main.py file, I had included the translation code in actions.py itself.

main.py I had attached just for reference purpose I am not using it in the rasa actions file.

Sure, I’ll add print() after every output, will let you know if I find anything.

Thanks Yashi

@yashi yashi, as per the code you have written it has translator mention (that’s why I asked), and how custom action know how to translate or you can use Google Translator API for the same. I guess it not giving you the result.

Ref: https://www.thepythoncode.com/article/translate-text-in-python