Rasa WebChat集成

时间:2018-11-07 10:01:15

标签: chatbot rasa-nlu rasa-core web-chat

通过观看以下视频,我已经使用Rasa-Core和Rasa-NLU在松弛状态下创建了一个聊天机器人:https://vimeo.com/254777331

在Slack.com上效果很好。但是我需要使用代码片段将此添加到我们的网站。当我查看时,可以发现RASA Webchat(https://github.com/mrbot-ai/rasa-webchat:一个用于与chatbot连接的简单webchat小部件)可用于将chatbot添加到网站。因此,我将此代码粘贴到了标记内的网站上。

    <div id="webchat"/>
    <script src="https://storage.googleapis.com/mrbot-cdn/webchat-0.4.1.js"></script>
    <script>
        WebChat.default.init({
            selector: "#webchat",
            initPayload: "/get_started",
            interval: 1000, // 1000 ms between each message
            customData: {"userId": "123"}, // arbitrary custom data. Stay minimal as this will be added to the socket
            socketUrl: "http://localhost:5500",
            socketPath: "/socket.io/",
            title: "Title",
            subtitle: "Subtitle",
            profileAvatar: "http://to.avat.ar",
        })
    </script> 

“ Run_app.py”是启动聊天机器人的文件(可在视频中找到:https://vimeo.com/254777331

Here is the code of Run_app.py :

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/weathernlu')
agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter)

input_channel = SlackInput('xoxp-381510545829-382263177798-381274424643-a3b461a2ffe4a595e35795e1f98492c9', #app verification token
                            'xoxb-381510545829-381150752228-kNSPU0X7HpaS8oJaqd77TPQE', # bot verification token
                            'B709JgyLSSyKoodEDwOiJzic', # slack verification token
                            True)

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

我想将此python聊天机器人连接到“ Rasa-webchat”,而不是使用Slack。但是我不知道该怎么做。我尝试到处寻找,但是在互联网上找不到任何有用的信息。有人能帮我吗?谢谢。

3 个答案:

答案 0 :(得分:1)

要将Rasa Core与您的网络聊天连接,请执行以下操作:

  1. 创建具有以下内容的凭据文件(credentials.yml):

    socketio:
        user_message_evt: user_uttered
        bot_message_evt: bot_uttered
    
  2. 使用以下命令启动Rasa Core(我假设您已经训练过模型):

    python -m rasa_core.run \
    --credentials <path to your credentials>.yml \
    -d <path to your trained core model> \
    -p 5500 # either change the port here to 5500 or to 5005 in the js script
    

由于您在凭据文件中指定了socketio配置,因此Rasa Core会自动启动SocketIO输入通道,您网站上的脚本随后将连接到该通道。

要添加NLU,您必须选择以下选项:

  1. 在您的Rasa Core -u <path to model>命令中使用run指定经过训练的NLU模型
  2. 运行单独的NLU服务器,并使用端点配置对其进行配置。 here对此进行了深入的解释

Rasa Core documentation也可能会为您提供帮助。

答案 1 :(得分:1)

要拥有一个网络频道,您需要一个可以发送和接收聊天内容的前端。可伸缩性思想有一个开源项目。首先看演示

demo

要将您的Rasa bot与该聊天室集成,可以安装聊天室项目,如下面的Github项目所示。它也适用于最新的0.11 Rasa版本。

Chatroom by Scalableminds

答案 2 :(得分:0)

您正面临依赖性问题,请查看您使用的 rasa 版本和网络聊天版本。

webchat 不支持 rasa 版本 2+