Can't Get my Custom Action to Work

Hello, Im new to Rasa. For my first project I am simply extending the demo bot and I have programmed it to respond to a few intents.

My main issue right now is trying to configure this bot to execute a custom action. The scenario where this happens is when the human user tells the bot they want to “book a hotel room”. This should execute a custom action that will eventually involve the bot making an API call, but right now I’ve set it to just respond with “This is a test”…see my files below.

STORIES:

## say goodbye

  • goodbye
    • utter_goodbye

## search path1

  • greet
    • utter_greet
  • book_hotel
    • utter_searching
    • action_get_hotel_link

DOMAIN:

action_names:

  • utter_greet
  • utter_goodbye
  • utter_searching
  • action_get_hotel_link

actions:

  • utter_greet
  • utter_goodbye
  • utter_searching
  • actions.BookHotel

intents:

  • greet
  • goodbye
  • affirm
  • book hotel

templates: utter_searching:

  • text: “Let me find that for you!”

utter_greet:

  • text: “Hey! How can I help you?”

utter_goodbye:

  • text: “Bye”

ACTIONS:

from future import absolute_import

from future import division

from future import unicode_literals

from rasa_core.actions.action import Action

class BookHotel (Action): def name(self): return ‘action_get_hotel_link’

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

    sp_data = "this is a test"
    
    dispatcher.utter_message(sp_data)
    return []

But for some reason, the bot is never able to relay the dispatcher message back to the user…

and I get this error in terminal:

“2019-06-12 10:57:30 ERROR rasa.core.processor - Encountered an exception while running action 'action_get_hotel_link '. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.”

Perhaps I messed up on my syntax somewhere…could someone point me in the right direction??

Thank you!

Hi @seansta ,

can you please post the whole content of your actions.py please? Was there any error while training with this domain file?

Regards

hello Julian, thank you for the response.

Here is the whole actions file:

When I train the model, I get no errors.

In fact the bot knows to execute the custom action, when it tries to that’s when I get the terminal error:

1 Like

Are you running an actions server in anther terminal process?

rasa run actions -vv is what I use.

Hi Jabberlope,

I’m not running that command in any terminal. Is that the problem?

Do I need to run that command before executing the “rasa x” command?

@seansta

It depends - if you have something like this in your endpoints file:

action_endpoint:
  url: http://localhost:5055/webhook

then yes, you need to do:

rasa run actions& 
rasa x

Could you try that?

Julian,

When I run “rasa run actions”…I get the follow error in terminal:

2019-06-12 12:49:02 INFO rasa_sdk.endpoint - Starting action endpoint server… 2019-06-12 12:49:02 ERROR rasa_sdk.executor - Failed to register package ‘actions’.

By the way, my endpoints file is blank. It is just the default file I got when I created a new rasa project, everything is commented out.

Ok, now I am curious. Could you please post your actions.py?

Then simply add:

action_endpoint:
  url: http://localhost:5055/webhook

to your endpoints file. I have to take a look at actions.py first.

Julian, there is an image of my actions.py file on my second post. I will try that.

But I just tried, this. Ran the “rasa run actions” command and then executed “rasa x” command in another terminal.

Retrained my model. Got these errors/warnings in the second terminal where I executed “rasa x”:

2019-06-12 12:56:15 WARNING rasa.core.training.dsl - Found unknown intent ‘book_hotel’ on line 8. Please, make sure th at all intents are listed in your domain yaml. 2019-06-12 12:56:15 WARNING rasa.core.domain - Failed to use action ‘action_get_hotel_link’ in history. Please make su re all actions are listed in the domains action list. If you recently removed an action, don’t worry about this warning. It should stop appearing after a while.

Here is my actions file, by the way. actions.py (408 Bytes)

Added that line to the endpoints file and still getting the same result.

Hi @seansta

Could you please change

from rasa_core.actions.action import Action

to

from rasa_sdk import Action

then we need to see your domain.yml and your stories.md - I smell that there is an error!

Regards Julian

Ok I changed, that in actions. Still nothing.

Here are my other files.domain.yml (384 Bytes) stories.md (153 Bytes)

I will investigate it tomorrow morning!

Thank you Julian :slight_smile:

Okay, let’s try something else. Start the bot by running:

rasa run -vv -m <path_to_model> --endpoints endpoints.yml --credentials credentials.yml --enable-api

After that, do a POST request with the body:

{
	"text": "I want to book a hotel room!"
}

to

http://localhost:5005/model/parse

and post the result here! We could then at least figure out from where the problem comes.

Hi Julian, thanks for the response.

I am trying to run a powershell script for this, how did I screw this up?

Hey,

you simply have not seen that

<path_to_model>

was a placeholder… you should insert the path to your model! :slight_smile:

Regards

Gotcha!

Here is the printout I got from PowerShell:

(env) PS C:\Users\UH80906\Desktop\testbot–1> cd C:\Users\UH80906\Desktop\testbot–1 virtualenv env .\env\Scripts\activate

rasa run -vv -m C:\Users\UH80906\Desktop\testbot–1\models --endpoints endpoints.yml --credentials credentials.yml --enable-api

$params = {

“I want to book a hotel room!”

}

Invoke-WebRequest -Uri http://localhost:5005/model/parse -Method POST -Body $params Using base prefix ‘c:\python\python36’ New python executable in C:\Users\UH80906\Desktop\testbot–1\env\Scripts\python.exe Installing setuptools, pip, wheel… done.

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see:

rasa : 2019-06-13 09:52:25 DEBUG rasa.model - Extracted model to ‘C:\Users\UH80906\AppData\Local\Temp\2\tmpum6cxb7l’. At line:6 char:1

  • rasa run -vv -m C:\Users\UH80906\Desktop\testbot–1\models --endpoint …
  •   + CategoryInfo          : NotSpecified: (2019-06-13 09:5...2\tmpum6cxb7l'.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

2019-06-13 09:52:25 DEBUG rasa.core.utils

  • Available web server routes: /conversations/<conversation_id>/messages POST add_message /conversations/<conversation_id>/tracker/events POST append_event /webhooks/rasa GET custom_webhook_RasaChatInput.health /webhooks/rasa/webhook POST custom_webhook_RasaChatInput.receive /webhooks/rest GET custom_webhook_RestInput.health /webhooks/rest/webhook POST custom_webhook_RestInput.receive /model/test/intents POST evaluate_intents /model/test/stories POST evaluate_stories /conversations/<conversation_id>/execute POST execute_action /domain GET get_domain / GET hello /model PUT load_model /model/parse POST parse /conversations/<conversation_id>/predict POST predict /conversations/<conversation_id>/tracker/events PUT replace_events /conversations/<conversation_id>/story GET retrieve_story /conversations/<conversation_id>/tracker GET retrieve_tracker /status GET status /model/predict POST tracker_predict /model/train POST train /model DELETE unload_model /version GET version 2019-06-13 09:52:25 INFO

root

root

  • Enabling coroutine debugging. Loop id 2082205605784. 2019-06-13 09:52:25 DEBUG

rasa.model

  • Extracted model to ‘C:\Users\UH80906\AppData\Local\Temp\2\tmp1g4fa655’. 2019-06-13 09:52:25 DEBUG rasa.model
  • Extracted model to ‘C:\Users\UH80906\AppData\Local\Temp\2\tmpbnfi4iir’.

post_response.txt (4.0 KB)

Hi,

I think that this is a misunderstanding… You have to separate those commands:

Open one PowerShell and type in:

rasa run -vv -m C:\Users\UH80906\Desktop\testbot–1\models --endpoints endpoints.yml --credentials credentials.yml --enable-api

Then open another PowerShell and type in:

$params = {

“I want to book a hotel room!”

}

Invoke-WebRequest -Uri http://localhost:5005/model/parse -Method POST -Body $params

Regards

Ok. This is the result:

post_response.txt (903 Bytes)