python - 使用 RASA 的 API 的正确方法是什么(rasa.core.processor - 遇到异常)?
问题描述
我安装了 rasa-demo 代码示例。为了打开 rasa API,我做了:
user@User:~/rasa-demo ‹master*›$ rasa run
No 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
2020-06-19 13:20:02 INFO root - Starting Rasa server on http://localhost:5005
2020-06-19 13:20:08 INFO absl - Using /var/folders/h5/9rj1zn8x4s59bk_mg_ktzv740000gn/T/tfhub_modules to cache modules.
2020-06-19 13:20:08 INFO absl - Downloading TF-Hub Module 'http://models.poly-ai.com/convert/v1/model.tar.gz'.
2020-06-19 13:20:26 INFO absl - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 22.35MB
2020-06-19 13:20:43 INFO absl - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 42.35MB
2020-06-19 13:21:02 INFO absl - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 82.35MB
2020-06-19 13:21:21 INFO absl - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 118.59MB
2020-06-19 13:21:40 INFO absl - Downloading http://models.poly-ai.com/convert/v1/model.tar.gz: 148.59MB
2020-06-19 13:21:41 INFO absl - Downloaded http://models.poly-ai.com/convert/v1/model.tar.gz, Total size: 152.02MB
2020-06-19 13:21:41 INFO absl - Downloaded TF-Hub Module 'http://models.poly-ai.com/convert/v1/model.tar.gz'.
2020-06-19 13:22:14 INFO root - Rasa server is up and running.
如何将聊天机器人作为 API 进行查询?我希望能够提出请求并通过请求进行对话,而不是使用 shell。到目前为止,当我尝试对 rasa 服务器进行 curl 操作时:
在:
user@User:~ $ curl -XPOST localhost:5005/webhooks/rest/webhook -d '{"message":"hi"}'
出去:
[]%
在 rasa 运行服务器上,我得到以下响应:
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]
2020-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.
2020-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]
2020-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.
它不工作。将 Rasa 服务器作为 API 请求的正确方法是什么?阅读文档后,我不清楚如何正确使用 API。
我也试过这个:
在:
import requests
response = requests.get('http://localhost:5005/webhooks/rest/webhook')
print(response)
print(response.headers)
print(response.content)
出去:
<Response [405]>
{'Connection': 'keep-alive', 'Keep-Alive': '5', 'Allow': 'POST', 'Access-Control-Allow-Credentials': 'true', 'Content-Length': '60', 'Content-Type': 'text/plain; charset=utf-8'}
b'Error: Method GET not allowed for URL /webhooks/rest/webhook'
解决方案
我最终弄清楚这就是您请求终点的方式:
localhost:5005/model/parse -s -d '{ "text": "hi" }'
文档应该更清楚。
推荐阅读
- kubernetes - 从 kubelet 批准证书后,kubenetes 无法获取节点信息
- javascript - 事件处理程序被多次触发
- c - 我在创建一个函数来搜索我的链接列表中的字符串时遇到问题
- json - 将 JSON 解析为 Dart 中的列表
- javascript - JavaScript 很难使用局部变量
- javascript - Bootstrap 5 选项卡和表单
- c - 结构的存储大小未知
- arrays - 将数据作为数组从函数存储并传递到另一个函数或代码
- python - AttributeError:“NoneType”对象在使用 Google 翻译时没有属性“组”
- google-apps-script - 插入带有 Google Apps 脚本的组织单位收到错误请求错误