跳转至

加入 Rasa 扩展支持

Botfront 里面增加对 Rasa 的 NLU component, channel, or policy 支持也是非常方便的。

通过 botfront init 指令创建的项目下都有一个 rasa 目录,里面存放所有 Rasa 运行所需要的额外文件,当你执行 botfront up 时,Rasa 的 docker 镜像将从这个目录下加载指定的文件。

示例:添加自定义 NLU 组件

默认在 rasa 目录下有一个 ignore_sample_component.py 文件,这个示例文件只是简单的在 NLU 结果中添加了一个 it_workds 字段。让我们看下它是如何工作的:

  1. 执行 botfront up 启动你的项目,然后执行 botfront watch,watcher 程序将会监控 rasaactions 两个目录下的文件变化,一旦这两个目录下的文件内容发生变化,docker 镜像会立即执行 rebuild/restart 动作让改动生效。
  2. ignore_sample_component.py 改成 sample_component.py (watcher 程序会忽略 ignore 开头的文件),Botfront 会 rebuild、restart 你的 docker Rasa 镜像,并通过 pip install 的形式加载你的自定义组件。
  3. 到 NLU -> Settings -> Pipeline 页面,然后在 YAML 文件中使用你的自定义组件: ```yaml{2} pipeline:
  4. name: sample_component.SampleComponent
  5. name: WhitespaceTokenizer ...
    4. 重训练模型
    5. 到 API 页面测试一下,你会看到 `it_works` works :)
    ```json{8}
    {
      "intent": {
        "name": "chitchat.greet",
        "confidence": 0.9417732358
      },
      "entities": [],
      "language": "en",
      "it_works": true, // It just works
      "intent_ranking": [
        {
          "name": "chitchat.greet",
          "confidence": 0.9417732358
        },
        {
          "name": "chitchat.bye",
          "confidence": 0.0582267493
        }
      ],
      "text": "hello"
    }
    

就是这么简单,创建自定义 connector 和 core policy 也是一样的流程。


最后更新: July 6, 2021