commune/compnt-rasa

component using rasa as nlu for commune/chatbot

v0.1.0 2019-12-29 13:39 UTC

This package is auto-updated.

Last update: 2024-02-29 03:59:03 UTC


README

本项目是commune/chatbotcommune/studio-hyperf的组件, 可将 Rasa 提供的 NLU 中间件引入项目.

composer require commune/compnt-rasa

注册 RasaComponent

CommuneChatbot 对 Rasa 服务做了基本的封装, 需要通过 Commune\Components\Rasa\RasaComponent 引入系统, 具体而言有三步:

  1. 配置数组引入 Commune\Components\Rasa\RasaComponent
  2. NLUComponent::$nluSerivces 处, 注册Commune\Components\Rasa\Services\RasaService
  3. 在配置数组 $chatbotConfig->host->sessionPipes 中引入中间件Commune\Components\Rasa\RasaSessionPipe
// 机器人配置数组 ChatbotConfig

return [
    ...

    'components' => [
        ...

        Commune\Components\Rasa\RasaComponent::class => [
            // rasa http api 地址
            'server' => 'localhost:5005',

            // 如果通过 jwt 验证的话
            'jwt' => '',

            // 意图的置信度, 高于 0.7 才加入 highlyPossibleIntent
            'threshold' => 70,

            // 语料库同步的目标文件位置
            'output' => __DIR__ .'/resources/rasa.md',

            // rasa domain.md 的文件位置
            'domainOutput' => __DIR__ . '/resources/domain.yml',

            // 使用 Guzzle 调用 Rasa api 时的配置
            'clientConfig' => [
                'timeout' => 0.3,
            ],
        ],

        NLUComponent::class => [
            'nluServices' => [
                ...
                Commune\Components\Rasa\Services\RasaService::class,
            ]

        ],
    ],

    ...

    'host' => [
        ...

        'sessionPipes' => [
            ...
            Commune\Components\Rasa\RasaSessionPipe::class,
        ]
        ...
    ],

]

同步语料库

Rasa 所需要的语料库, 格式在 Rasa training data format 可以查看. CommuneChatbot 的本地语料库设计参考了 Rasa 定义的格式.

使用 Commune\Components\Rasa\Services\RasaService 可以直接将本地语料库同步到 rasa 的配置文件中.

具体内容请查看 开发手册.

CommuneChatbot 开发了一批用多轮对话管理机器人自己的工具.

请选择您要使用的开发工具:  (1)

[1] nlu 语料库管理

> 1

选择功能 (1)

[1] 查看NLU命中的意图
[2] 同步语料库到NLU
[3] 同步语料库到本地存储
[4] 管理意图的语料样本

> 2

Commune\Components\Rasa\Services\RasaService : success