如何监听特定端口的数据?

时间:2018-06-05 17:22:52

标签: python server rasa-core

我喜欢从this tutorial创建一个聊天机器人,但似乎Rasa版本太旧了,突然命令不起作用。

我知道如何通过Slack恢复和响应消息,但我不知道如何从我使用聊天界面开发的Web应用程序中执行此操作。

使用Slack,我启动了以下脚本:

input_channel

我知道我必须修改public class ApiUtils { private ApiUtils() {} public static final String BASE_URL = "http://jsonplaceholder.typicode.com/"; public static APIServices getAPIService() { return RetrofitClient.getClient(BASE_URL).create(APIServices.class); } } 以便他在正确的端口听到,但我真的不知道如何。

Here是HttpInputChannel来自

的地方

1 个答案:

答案 0 :(得分:0)

如果您已准备好对话框模型和nlu模型,则可以像这样运行Rasa核心

$python -m rasa_core.server -d <DIALOGUE_MODEL_PATH> -u <NLU_MODEL_PATH> --debug -o out.log --cors *

然后在另一个终端,在下面做,你会收到回复

$curl -XPOST localhost:5005/conversations/default/respond -d '{"query":"Hello"}'

如果发件人ID对您很重要,那么如果您想将nad作为发件人ID传递,则在命令下面

$curl -XPOST localhost:5005/conversations/nad/respond -d '{"query":"Hello"}'

适用于NLU版本0.12.3和核心版本0.9.0a6

<强>更新 如果您正在尝试围绕它构建UI

在终端

中运行
$python -m rasa_core.server -d <DIALOGUE_MODEL_PATH> -u <NLU_MODEL_PATH> --debug -o out.log --cors *

在您的服务器中

import requests
import json

data = '{"query":"hello"}'
response = requests.post('http://localhost:5005/conversations/default/respond', data=data)
json_response = response.json()
print (json_response[0]['text'])

这应该在您的终端输出hello的回复。