变更内容#
本指南非全面地概述了 Colang 2.0 中最重要的变更。
术语#
为了限制学习曲线,Colang 2.0 尽可能多地借用 Python 中的术语
每一段 Colang 代码都称为脚本。
单个
.co
文件称为模块。Colang 文件的文件夹,可能带有子文件夹,称为包。
模块和包可以被导入。
语法变更#
删除
define
、execute
关键字。添加
flow
、match
、send
、start
、await
、activate
关键字。支持装饰器。
when
/or when
代替when
/else when
。删除子流程。
定义用户和机器人意图#
不再支持特殊的 define user ...
和 define bot ...
语法。当定义示例话语时,在 Colang 2.0 中,您必须使用更显式的语法
flow user expressed greeting
user said "hi" or user said "hello"
flow user expressed greeting
user said "hi"
or user said "hello"
or user said "Good evening!"
or user said "Good afternoon!"
为什么?例如,现在您可以混合其他类型的事件和模态,例如,user gesture "wave"
。
类似地,对于机器人意图
flow bot express greeting
bot say "Hello world!"
or bot say "Hi there!"
流程命名约定#
对来自“系统外部”的事件进行建模的流程使用过去时命名,例如,user said
、user expressed greeting
等。在机器人端,它们表示需要采取的动作,并使用祈使语气,例如,bot say
、bot express greeting
、bot refuse to respond
等。有关更多详细信息,请参阅 流程命名约定。
生成运算符#
Colang 2.0 引入了 ...
运算符,也称为“生成”运算符。当 Colang 脚本的某部分需要在运行时动态生成时,可以使用此运算符。通常,这是使用 LLM 完成的。
...
运算符支持使用自然语言流程,其中流程的文档字符串用于生成流程的内容。
激活流程#
在 Colang 1.0 中,所有流程默认都是激活的。在 Colang 2.0 中,流程必须显式激活。现在还有一个 main
流程,默认情况下是激活的,并且是入口点。
入口点#
在 Colang 1.0 中,Colang 脚本没有明确的入口点。在 Colang 2.0 中,main
流程是入口点。main
流程触发 Colang 包中使用的所有其他流程的激活。
导入机制#
Colang 2.0 添加了类似于 Python 的导入机制。存在于 COLANGPATH
中的任何 Colang 模块或包都可以使用 import
语句导入。与 Python 不同,目前 Colang 2.0 仅提供模块/包级别的导入,即,您不能仅导入特定的流程。这将在未来的版本中添加。
标准库#
Colang 2.0 现在有一个标准库
core
:一组与用户和机器人话语相关的核心流程,例如,user said
、bot say
。llm
:与使用 LLM 驱动交互相关的流程。timing
:与时间相关的流程,例如,wait
、user was silent $time_s
。guardrails
:支持添加 guardrails,即,检查用户输入、机器人输出等。avatars
:支持控制交互式头像。utils
:一小组实用流程。
异步操作#
在 Colang 1.0 中,动作只能同步执行,阻塞流程。此外,也没有办法并行启动两个动作。例如,如果您想并行运行多个输入轨道,这一点尤其重要。
在 Colang 2.0 中,execute
关键字已替换为 await
,类似于 Python。此外,您可以使用 start
启动一个动作而不阻塞流程。
命名约定#
Colang 2.0 使用以下命名约定: - 流程名称:小写,可以有空格,应自然易读。 - 动作名称:驼峰式,必须以 “Action” 结尾。 - 事件名称:驼峰式。
对于标记动作开始和结束的事件,有一些约定:Start...Action
、...ActionStarted
、...ActionFinished
。
多模态#
Colang 2.0 支持对多模态交互进行建模,而不仅仅是基于文本的交互(例如,user gesture
、bot gesture
、bot posture
等)
变量#
在 Colang 1.0 中,所有变量默认都是全局的。在 Colang 2.0 中,所有变量默认都是局部的。要使变量成为全局变量,可以使用 global
关键字。
Colang 2.0 中没有默认的全局变量。
字符串格式化#
不再支持内联 "Hello there, $name!"
。您必须始终将变量包装在花括号内,类似于 python "Hello there, {$name}!"
。
LLM 调用#
在 Colang 1.0 中,一旦您定义了用户意图,对话轨道将自动激活,并且将使用 LLM。在 Colang 2.0 中,要使用 LLM,您必须显式激活该机制
flow main
activate llm continuation
Python API#
Colang 2.0 添加了对显式 “状态对象” 的支持。对于跨越多个回合/事件的交互,每次处理后都会返回一个状态对象,并且需要在下一个处理周期中将其传回。
从 alpha 版本到 beta 版本的重大更改#
- 元标签
# meta: user intent
->@meta(user_intent=True)
(也包括user_action
、bot_intent
、bot_action
)# meta: exclude from llm
->@meta(exclude_from_llm=True)
- 交互循环 ID
# meta: loop_id=<loop_id>
->@loop("<loop_id>")
- Or when 语句
orwhen
->or when
- NLD 指令
"""<NLD>"""
->..."<NLD>"
- 内部事件参数重命名
flow_start_uid
->flow_instance_uid
- 正则表达式
r"<regex>"
->regex("<regex>")
- 字符串中的表达式
"{{<expression>}}"
->"{<expression>}"
- Colang 函数名称更改
findall
->find_all
- Colang Core Library 的机器人特定副本
ccl_*.co 文件已弃用,应从机器人文件夹中删除。它被 NeMo Guardrails 中包含的 Colang 标准库取代,并且可以导入(例如
import core
或import llm
)。请参阅接下来标准库流程的新名称映射。
- 标准库流程名称更改
catch colang errors
->notification of colang errors
(core.co) -> colang 错误通知 (core.co)catch undefined flows
->notification of undefined flow start
(core.co) -> 未定义流程启动通知 (core.co)catch unexpected user utterance
->notification of unexpected user utterance
(core.co) -> 意外用户话语通知 (core.co)poll llm request response
->polling llm request response
(llm.co) -> 轮询 llm 请求响应 (llm.co)trigger user intent for unhandled user utterance
->generating user intent for unhandled user utterance
(llm.co) -> 为未处理的用户话语生成用户意图 (llm.co)generate then continue interaction
->llm continue interaction
(llm.co) -> llm 继续交互 (llm.co)track bot talking state
->tracking bot talking state
(core.co) -> 跟踪机器人说话状态 (core.co)track user talking state
->tracking user talking state
(core.co) -> 跟踪用户说话状态 (core.co)track unhandled user intent state
->tracking unhandled user intent state
(llm.co) -> 跟踪未处理的用户意图状态 (llm.co)track visual choice selection state
->track visual choice selection state
(avatars.co) -> 跟踪视觉选择选择状态 (avatars.co)track user utterance state
->tracking user talking state
(core.co) -> 跟踪用户说话状态 (core.co)track bot utterance state
->tracking bot talking state
(core.co) -> 跟踪机器人说话状态 (core.co)interruption handling bot talking
->handling bot talking interruption
(avatars.co) -> 处理机器人说话中断 (avatars.co)generate then continue interaction
->llm continue interaction
(llm.co) -> llm 继续交互 (llm.co)respond to unhandled user intent
->continuation on unhandled user intent
(llm.co) -> 继续处理未处理的用户意图 (llm.co)manage listening posture
->managing listening posture
(avatars.co) -> 管理倾听姿势 (avatars.co)manage talking posture
->managing talking posture
(avatars.co) -> 管理说话姿势 (avatars.co)manage thinking posture
->managing thinking posture
(avatars.co) -> 管理思考姿势 (avatars.co)manage attentive posture
-> No replacement (copy to your bot script if needed) -> manage attentive posture (无替换,如果需要,复制到您的机器人脚本)manage bot postures
->managing bot postures
(avatars.co) -> 管理机器人姿势 (avatars.co)track user presence state
-> No replacement (copy to your bot script if needed) -> track user presence state (无替换,如果需要,复制到您的机器人脚本)user became no longer present
-> No replacement (copy to your bot script if needed) -> user became no longer present (无替换,如果需要,复制到您的机器人脚本)