pythonchatbotrasa-nlurasa-corerasa

Encountering error running custom actions in rasa


I recently started working on rasa. My chatbot is simple. Whenever a user asks a question, the bot filters data from a sqlite3 database and return the result. I added the training examples, created stories for flow, and wrote a custom action to filter data from the database. for the custom action, I specified an endpoint and started the action server. This is my code so far

actions.py

from typing import Any, Text, Dict, List
from rasa_core_sdk import Action, Tracker
import sqlite3

class TestAction(Action):

    def name(self) -> Text:
        return "action_testAction"

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

        UserId = tracker.get_slot('UserID')
        query = 'SELECT User_name FROM sales WHERE UserID=?'

        conn = sqlite3.connect("test.db")
        cursor = conn.cursor()
        cursor.execute(query, (UserId,))
        name = cursor.fetchall()

        msg = 'Hello {}!'.format(name)
        dispatcher.utter_message(msg)

endpoints.yml

action_endpoint:
  url: "http://localhost:5055/"

for running the endpoint, I ran the following code in a separate terminal window

python -m rasa_sdk --actions actions

But when I run the program with rasa shell --endpoints endpoints.yml command based on this link, I get the following error

rasa.core.processor  - Encountered an exception while running action 'action_testAction'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.

This is what my action endpoint server returned

127.0.0.1 - - [2019-09-09 11:07:23] "POST / HTTP/1.1" 404 342 0.005443

I am not sure, what I am doing wrong. I checked the code actions.py file. I dont seem to have made any errors there.

[edit 1]

I was looking online and came across this tutorial.

In this tutorial, the endpoint is defined as

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

Now i tried the same with my code. when I run the chatbot with the updated code, I get the following exception in the action_server

Exception: No registered Action found for name 'action_testAction'.

[edit 2]

results of running the actions server i debug mode

(base) SASHAANKs-MacBook-Pro:speechbot2 sashaanksekar$ rasa run actions -vv
2019-09-09 19:38:33 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2019-09-09 19:38:38 INFO     rasa_sdk.endpoint  - Action endpoint is up and running. on ('0.0.0.0', 5055)
2019-09-09 19:39:06 DEBUG    rasa_sdk.executor  - Received request to run 'action_testAction'
2019-09-09 19:39:06 ERROR    flask.app  - Exception on /webhook [POST]
Traceback (most recent call last):
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/flask_cors/decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/rasa_sdk/endpoint.py", line 59, in webhook
    response = executor.run(action_call)
  File "/Users/sashaanksekar/anaconda3/lib/python3.7/site-packages/rasa_sdk/executor.py", line 246, in run
    "No registered Action found for name '{}'.".format(action_name)
Exception: No registered Action found for name 'action_testAction'.

Please help me


Solution

  • The reason you're getting the Exception: No registered Action found for name 'action_testAction'. error is because of your first exception when running the action server i.e. because of this:

    rasa.core.processor  - Encountered an exception while running action 'action_testAction'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
    

    Try running the action server in debug mode using the debug flag -vv like rasa run actions -vv to see where the problem in your code is. (The problem may be because you may not have imported Action or sqlite3 or whatever else).

    Hope that helps.

    Edit:

    Make sure that the name of the action file matches.

    Running rasa run actions --actions action -vv yeilds

    (chatbot) PS C:\Users\user\Documents\Python\rasa-test> python -m rasa_sdk --actions action -vv
    2019-09-09 21:02:56 INFO     rasa_sdk.endpoint  - Starting action endpoint server... 
    2019-09-09 21:02:56 INFO     rasa_sdk.executor  - Registered function for 'action_testAction'.
    2019-09-09 21:02:56 INFO     rasa_sdk.endpoint  - Action endpoint is up and running. on ('0.0.0.0', 5055)       
    

    action.py

    import sqlite3
    
    from rasa_sdk import Action
    
    class TestAction(Action):
    
        def name(self):
            return "action_testAction"
    
        def run(self, dispatcher, tracker, domain):
    
            UserId = tracker.get_slot('UserID')
            query = 'SELECT User_name FROM sales WHERE UserID=?'
    
            conn = sqlite3.connect("test.db")
            cursor = conn.cursor()
            cursor.execute(query, (UserId,))
            name = cursor.fetchall()
    
            msg = 'Hello {}!'.format(name)
            dispatcher.utter_message(msg)