What’s Changed#
本指南概述了 Colang 2.0 中最重要的非全面更改。
Terminology#
为了限制学习曲线,Colang 2.0 尽可能地借鉴了 Python 的术语
每一段 Colang 代码都称为脚本。
单个
.co
文件称为模块。Colang 文件的文件夹,可能带有子文件夹,称为包。
模块和包可以导入。
Syntax Changes#
删除
define
、execute
关键字。添加
flow
、match
、send
、start
、await
、activate
关键字。支持装饰器。
when
/or when
代替when
/else when
。删除子流。
Defining User and Bot Intents#
不再支持特殊的 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"
。
同样,对于 bot 意图
flow bot express greeting
bot say "Hello world!"
or bot say "Hi there!"
Flow naming conventions#
对来自“系统外部”的事件进行建模的流使用过去时命名,例如 user said
、user expressed greeting
等。在 bot 端,它们表示需要采取的动作,并使用命令式形式,例如 bot say
、bot express greeting
、bot refuse to respond
等。有关更多详细信息,请参阅 流命名约定。
The Generation Operator#
Colang 2.0 引入了 ...
运算符,也称为“生成”运算符。当 Colang 脚本的一部分需要在运行时动态生成时,可以使用它。通常,这是使用 LLM 完成的。
...
运算符支持使用自然语言流,其中流的文档字符串用于生成流的内容。
Active Flows#
在 Colang 1.0 中,所有流默认都是激活的。在 Colang 2.0 中,流必须显式激活。现在还有一个 main
流,默认情况下激活,并且是入口点。
Entry Point#
在 Colang 1.0 中,Colang 脚本没有明确的入口点。在 Colang 2.0 中,main
流是入口点。main
流触发 Colang 包中使用的所有其他流的激活。
Import Mechanism#
Colang 2.0 添加了类似于 python 的导入机制。可以使用 import
语句导入 COLANGPATH
中存在的任何 Colang 模块或包。与 Python 不同,目前,Colang 2.0 仅提供模块/包级别的导入,即,您不能仅导入特定的流。这将在未来的版本中添加。
Standard Library#
Colang 2.0 现在有一个标准库
core
:一组与用户和 bot 话语相关的核心流,例如user said
、bot say
。llm
:与使用 LLM 驱动交互相关的流。timing
:时间相关的流,例如wait
、user was silent $time_s
。guardrails
:支持添加防护栏,即检查用户输入、bot 输出等。avatars
:支持控制交互式头像。utils
:一小组实用程序流。
Asynchronous Actions#
在 Colang 1.0 中,动作只能同步执行,从而阻塞流。此外,无法并行启动两个动作。如果您想并行运行多个输入轨道,这一点尤其重要。
在 Colang 2.0 中,execute
关键字已替换为 await
,类似于 Python。此外,您可以使用 start
启动一个动作而不会阻塞流。
Naming Conventions#
Colang 2.0 使用以下命名约定:- 流名称:小写,可以有空格,应自然阅读。- 动作名称:驼峰式,必须以 “Action” 结尾。- 事件名称:驼峰式。
对于标记动作开始和结束的事件,有一些约定:Start...Action
、...ActionStarted
、...ActionFinished
。
Multi-modal#
Colang 2.0 支持对多模态交互进行建模,而不仅仅是基于文本的交互(例如,user gesture
、bot gesture
、bot posture
等)
Variables#
在 Colang 1.0 中,所有变量默认都是全局的。在 Colang 2.0 中,所有变量默认都是局部的。要使变量成为全局变量,您可以使用 global
关键字。
Colang 2.0 中没有默认的全局变量。
String formatting#
不再支持内联 "Hello there, $name!"
。您必须始终将变量包装在花括号内,类似于 python "Hello there, {$name}!"
。
LLM invocation#
在 Colang 1.0 中,一旦您定义了用户意图,对话轨道将自动激活,并且将使用 LLM。在 Colang 2.0 中,要使用 LLM,您必须显式激活该机制
flow main
activate llm continuation
Python API#
Colang 2.0 添加了对显式“状态对象”的支持。对于跨多个回合/事件的交互,每次处理后都会返回一个状态对象,并且需要在下一个处理周期中将其传回。
Breaking changes from alpha to beta version#
- 元标签
# 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 的 Bot 特定副本
ccl_*.co 文件已弃用,应从 bot 文件夹中删除。它被 NeMo Guardrails 中包含的 Colang 标准库取代,可以导入(例如
import core
或import llm
)。请参阅下一个标准库流的新名称映射。
- 标准库流名称更改
catch colang errors
->notification of colang errors
(core.co)catch undefined flows
->notification of undefined flow start
(core.co)catch unexpected user utterance
->notification of unexpected user utterance
(core.co)poll llm request response
->polling llm request response
(llm.co)trigger user intent for unhandled user utterance
->generating user intent for unhandled user utterance
(llm.co)generate then continue interaction
->llm continue interaction
(llm.co)track bot talking state
->tracking bot talking state
(core.co)track user talking state
->tracking user talking state
(core.co)track unhandled user intent state
->tracking unhandled user intent state
(llm.co)track visual choice selection state
->track visual choice selection state
(avatars.co)track user utterance state
->tracking user talking state
(core.co)track bot utterance state
->tracking bot talking state
(core.co)interruption handling bot talking
->handling bot talking interruption
(avatars.co)generate then continue interaction
->llm continue interaction
(llm.co)respond to unhandled user intent
->continuation on unhandled user intent
(llm.co)manage listening posture
->managing listening posture
(avatars.co)manage talking posture
->managing talking posture
(avatars.co)manage thinking posture
->managing thinking posture
(avatars.co)manage attentive posture
-> No replacement (copy to your bot script if needed)manage bot postures
->managing bot postures
(avatars.co)track user presence state
-> No replacement (copy to your bot script if needed)user became no longer present
-> No replacement (copy to your bot script if needed)