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

How to listen to the data in a specific port?

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

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

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

from rasa_core.channels import HttpInputChannel
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
#from rasa_slack_connector import SlackInput

nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/moodnlu')
agent = Agent.load('./models/dialogue',interpreter = nlu_interpreter)


# With Slack
# https://api.slack.com/apps/AASPDV196/oauth?
#input_channel = SlackInput('OAuth Access Token','Bot User OAuth Access Token', 'Verification Token',True)

#agent.handle_channel(HttpInputChannel(5004,'/',input_channel))

# With inner app
input_channel = SlackInput('OAuth Access Token','Bot User OAuth Access Token', 'Verification Token',True)
agent.handle_channel(HttpInputChannel(5000,'/',input_channel))

我知道我必须修改 input_channel 以便他在正确的端口中听到,但我真的不知道该怎么做。

Here 是 HttpInputChannel 的来源

如果你准备好了对话模型和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 的回复。