【问题标题】:How can I use the output of a python script as RASA’s input instead of the usual user input?如何使用 python 脚本的输出作为 RASA 的输入,而不是通常的用户输入?
【发布时间】:2019-08-23 17:38:29
【问题描述】:

我目前正在使用 RASA 并开发了一个可以工作的聊天机器人。我的项目的一部分是使用语音到文本的识别,我用 Python 编写了一个工作代码,它返回用户所说的文本。 我想使用该文本作为 RASA 的输入,而不是像往常一样书写。

我看到与输入通道有关,但我只看到其他 Web 服务的输入,并且无法仅使用本地脚本来解决。

谢谢你的建议,

LM

【问题讨论】:

标签: python chatbot rasa


【解决方案1】:

您可以为此尝试 rasa REST API。确保您在 endpoints.yml 中有 action_endpoint url。通常是

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

然后确保您的 rasa 机器人已启动,如果有任何自定义操作,请同时启动该服务器。

启动你的webhook后,你可以简单的调用

http://localhost:5005/webhooks/rest/webhook

在有效负载中,您必须将其放在有效负载下方

messagePayload = {
    sender: 'default',
    message: 'Your message is here'
  }

最后添加 httpheader 内容类型为 application/json 如下所示

'Content-Type':  'application/json'

现在你的机器人可以正常工作了。

tldr;

如果您在 python 中使用 request 进行 api 调用,您可以尝试以下代码。

import requests

API_ENDPOINT = "http://localhost:5005/webhooks/rest/webhook"

messagePayload = {
        sender: 'default',
        message: 'Your message is here'
      }


r = requests.post(url = API_ENDPOINT, data = messagePayload) 

【讨论】:

  • 非常感谢,我会试试那个解决方案:)
【解决方案2】:

仅使用库中已有的 Rest API 怎么样。
为此,您只需要填写查询参数即可,您可以使用脚本执行此操作,而不是编写自定义输入通道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2023-01-23
    • 2017-10-02
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多