我最近开始研究 rasa。我的聊天机器人很简单。每当用户提出问题时,机器人都会从sqlite3
数据库中过滤数据并返回结果。我添加了训练示例,为流程创建了故事,并编写了一个自定义操作来过滤数据库中的数据。对于自定义操作,我指定了一个端点并启动了操作服务器。到目前为止,这是我的代码
动作.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)
端点.yml
action_endpoint:
url: "http://localhost:5055/"
为了运行端点,我在单独的终端窗口中运行了以下代码
python -m rasa_sdk --actions actions
但是当我使用rasa shell --endpoints endpoints.yml
基于此链接的命令运行程序时,出现以下错误
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.
这是我的动作端点服务器返回的
127.0.0.1 - - [2019-09-09 11:07:23] "POST / HTTP/1.1" 404 342 0.005443
我不确定,我做错了什么。我检查了代码 actions.py 文件。我似乎没有在那里犯任何错误。
[编辑 1]
我在网上找了这个教程。
在本教程中,端点定义为
action_endpoint:
url: "http://localhost:5055/webhook"
现在我用我的代码尝试了同样的方法。当我使用更新的代码运行聊天机器人时,在 action_server 中出现以下异常
Exception: No registered Action found for name 'action_testAction'.
[编辑 2]
运行操作服务器的结果我调试模式
(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'.
请帮我