您好,欢迎来到花图问答。
搜索
您的当前位置:首页Rasa 入门教程 Core 系列(三)

Rasa 入门教程 Core 系列(三)

来源:花图问答
rasa_tutorial_core_background.png

有三种方式可以管理这些话术:

  • 将话术存储在 domain 文件中;
  • 将检索动作响应作为训练数据的一部分;
  • 创建自定义 NLG 服务以生成响应。

本文的目录结构:

  1. 将话术存储在 domain 文件中
  2. 为机器人响应创建 NLG 服务

1. 将话术存储在 domain 文件中

响应管理的默认方式是将话术存储在 domain 文件中,然后包含该文件中所有自定义动作、可用实体、槽位和意图的引用。

# all hashtags are comments :)
intents:
 - greet
 - default
 - goodbye
 - affirm
 - thank_you
 - change_bank_details
 - simple
 - hello
 - why
 - next_intent

entities:
 - name

slots:
  name:
    type: text

templates:
  utter_greet:
    - text: "hey there {name}!"  # {name} will be filled by slot (same name) or by custom action
  utter_channel:
    - text: "this is a default channel"
    - text: "you're talking to me on slack!"  # if you define channel-specific utterances, the bot will pick
      channel: "slack"                        # from those when talking on that specific channel
  utter_goodbye:
    - text: "goodbye 😢"   # multiple templates - bot will randomly pick one of them
    - text: "bye bye 😢"
  utter_default:   # utterance sent by action_default_fallback
    - text: "sorry, I didn't get that, can you rephrase it?"

actions:
  - utter_default
  - utter_greet
  - utter_goodbye

2. 为机器人响应创建 NLG 服务

在某些工作流程中,仅仅对机器人进行重新训练来更改文本副本可能不是最佳选择,因此,Rasa Core 提供了将生成响应和对话学习分开的功能。

助手仍将可以预测动作并根据过去的对话记录对用户的输入做出响应,助手发送给用户的响应信息是在 Rasa Core 之外生成的。

如果助手想向用户发送消息,它可以通过 post 请求调用外部 HTTP 服务器,你需要创建一个 endpoints.yml 文件并肩其传给 runserver 脚本,endpoints.yml 文件内容如下:

nlg:
  url: http://localhost:5055/nlg    # url of the nlg endpoint
  # you can also specify additional parameters, if you need them:
  # headers:
  #   my-custom-header: value
  # token: "my_authentication_token"    # will be passed as a get parameter
  # basic_auth:
  #   username: user
  #   password: pass
# example of redis external tracker store config
tracker_store:
  type: redis
  url: localhost
  port: 6379
  db: 0
  password: password
  record_exp: 30000
# example of mongoDB external tracker store config
#tracker_store:
  #type: mongod
  #url: mongodb://localhost:27017
  #db: rasa
  #user: username
  #password: password

现在通过以下命令来启动服务器:

$ rasa run --enable-api -m examples/babi/models --log-file out.log --endpoints endpoints.yml

post 发送到端点的请求主体如下所示:

{
  "tracker": {
    "latest_message": {
      "text": "/greet",
      "intent_ranking": [
        {
          "confidence": 1.0,
          "name": "greet"
        }
      ],
      "intent": {
        "confidence": 1.0,
        "name": "greet"
      },
      "entities": []
    },
    "sender_id": "22ae96a6-85cd-11e8-b1c3-f40f241f6547",
    "paused": false,
    "latest_event_time": 1531397673.293572,
    "slots": {
      "name": null
    },
    "events": [
      {
        "timestamp": 1531397673.291998,
        "event": "action",
        "name": "action_listen"
      },
      {
        "timestamp": 1531397673.293572,
        "parse_data": {
          "text": "/greet",
          "intent_ranking": [
            {
              "confidence": 1.0,
              "name": "greet"
            }
          ],
          "intent": {
            "confidence": 1.0,
            "name": "greet"
          },
          "entities": []
        },
        "event": "user",
        "text": "/greet"
      }
    ]
  },
  "arguments": {},
  "template": "utter_greet",
  "channel": {
    "name": "collector"
  }
}

然后,端点需要使用生成的响应进行响应用户:

{
    "text": "hey there",
    "buttons": [],
    "image": null,
    "elements": [],
    "attachments": []
}

然后,Rasa 将使用此响应发送给用户。


备注:转载请注明出处。

如发现错误,欢迎留言指正。

Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务