使用 RASA API 的正确方法是什么(rasa.core.processor - 遇到异常)?

tum*_*eed 2 python nlp python-requests rasa-core rasa

我安装了 rasa-demo 代码示例。为了打开 rasa API,我做了:

\n\n
user@User:~/rasa-demo \xe2\x80\xb9master*\xe2\x80\xba$ rasa run\nNo chat connector configured, falling back to the REST input channel. To connect your bot to another channel, read the docs here: https://rasa.com/docs/rasa/user-guide/messaging-and-voice-channels\n2020-06-19 13:20:02 INFO     root  - Starting Rasa server on http://localhost:5005\n2020-06-19 13:20:08 INFO     absl  - Using /var/folders/h5/9rj1zn8x4s59bk_mg_ktzv740000gn/T/tfhub_modules to cache modules.\n2020-06-19 13:20:08 INFO     absl  - Downloading TF-Hub Module \'http://models.poly-ai.com/convert/v1/model.tar.gz\'.\n2020-06-19 13:20:26 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 22.35MB\n2020-06-19 13:20:43 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 42.35MB\n2020-06-19 13:21:02 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 82.35MB\n2020-06-19 13:21:21 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 118.59MB\n2020-06-19 13:21:40 INFO     absl  - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 148.59MB\n2020-06-19 13:21:41 INFO     absl  - Downloaded http://models.poly-ai.com/convert/v1/model.tar.gz, Total size: 152.02MB\n2020-06-19 13:21:41 INFO     absl  - Downloaded TF-Hub Module \'http://models.poly-ai.com/convert/v1/model.tar.gz\'.\n2020-06-19 13:22:14 INFO     root  - Rasa server is up and running.\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何以 API 形式查询聊天机器人?我希望能够发出请求并通过请求进行对话,而不是使用 shell。到目前为止,当我尝试对 rasa 服务器进行卷曲时:

\n\n

在:

\n\n
user@User:~ $ curl -XPOST localhost:5005/webhooks/rest/webhook -d \'{"message":"hi"}\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

出去:

\n\n
[]%\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 rasa run 服务器上,我得到以下响应:

\n\n
2020-06-19 13:23:17 ERROR    rasa.core.actions.action  - Failed to run custom action \'action_greet_user\'. Couldn\'t connect to the server at \'http://localhost:5055/webhook\'. Is the server running? Error: Cannot connect to host localhost:5055 ssl:default [Connection refused]\n2020-06-19 13:23:17 ERROR    rasa.core.processor  - Encountered an exception while running action \'action_greet_user\'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.\n2020-06-19 13:24:04 ERROR    rasa.core.actions.action  - Failed to run custom action \'action_greet_user\'. Couldn\'t connect to the server at \'http://localhost:5055/webhook\'. Is the server running? Error: Cannot connect to host localhost:5055 ssl:default [Connection refused]\n2020-06-19 13:24:04 ERROR    rasa.core.processor  - Encountered an exception while running action \'action_greet_user\'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.\n
Run Code Online (Sandbox Code Playgroud)\n\n

它不起作用。请求 Rasa 服务器作为 API 的正确方法是什么?阅读文档后,我不清楚如何正确使用 API。

\n\n

我也尝试过这个:

\n\n

在:

\n\n
import requests\n\nresponse = requests.get(\'http://localhost:5005/webhooks/rest/webhook\') \nprint(response) \nprint(response.headers) \nprint(response.content)\n
Run Code Online (Sandbox Code Playgroud)\n\n

出去:

\n\n
<Response [405]>\n{\'Connection\': \'keep-alive\', \'Keep-Alive\': \'5\', \'Allow\': \'POST\', \'Access-Control-Allow-Credentials\': \'true\', \'Content-Length\': \'60\', \'Content-Type\': \'text/plain; charset=utf-8\'}\nb\'Error: Method GET not allowed for URL /webhooks/rest/webhook\'\n
Run Code Online (Sandbox Code Playgroud)\n

tum*_*eed 5

我最终发现这就是你请求终点的方式:

localhost:5005/model/parse -s -d '{ "text": "hi" }'
Run Code Online (Sandbox Code Playgroud)

文档应该更清晰。