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

2024-10-02 06:26:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从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的来源


Tags: fromcoreimporttokeninputaccesschannelslack
1条回答
网友
1楼 · 发布于 2024-10-02 06:26:45

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

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

然后在另一个终端中,执行下面的操作,您将得到一个响应

^{pr2}$

如果发送方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的回复。在

相关问题 更多 >

    热门问题