多模态 Rails#

本节介绍如何在 Colang 2.0 中创建多模态 rails。

定义#

多模态 rails 是一种考虑多种类型输入/输出模态(例如,文本、语音、手势、姿势、图像)的 rails。

用法#

下面的示例展示了如何控制交互式头像的问候行为。

注意

Colang 标准库 (CSL) 包含一个 avatars 模块,其中包含用于多模态事件和操作的流程,以实现交互式头像用例。

examples/v2_x/tutorial/multi_modal/main.co#
 1import core
 2import avatars
 3
 4flow main
 5  user expressed greeting
 6  bot express greeting
 7
 8flow user expressed greeting
 9  user expressed verbal greeting
10    or user gestured "Greeting gesture"
11
12flow user expressed verbal greeting
13  user said "hi"
14    or user said "hello"
15
16flow bot express greeting
17  bot express verbal greeting
18    and bot gesture "Smile and wave with one hand."
19
20flow bot express verbal greeting
21  bot say "Hi there!"
22    or bot say "Welcome!"
23    or bot say "Hello!"

在上面的流程中,第 9 行和第 17 行使用预定义的流程 user gesturedbot gesture,它们匹配用户手势并控制 bot 手势。

底层原理#

在底层,使用上述 Colang 脚本的交互式系统需要生成 GestureUserActionFinished 事件(这是 user gestured 流程正在等待的事件),并且知道如何处理 StartGestureBotAction 事件(这是 bot gesture 流程触发的事件)。

测试#

要使用 NeMo Guardrails CLI 测试上述逻辑,您可以通过以 / 开头发送消息来手动发送事件

$ nemoguardrails chat --config=examples/v2_x/tutorial/guardrails_1

> hi

Welcome!

Gesture: Smile and wave with one hand.

> /GestureUserActionFinished(gesture="Greeting gesture")

Hi there!

Gesture: Smile and wave with one hand.

下一个示例 将展示如何定义输入 rails。