开发与调试#
当前,Colang 故事设计和构建环境相当有限,但未来将会改进。
集成开发环境 (IDE)#
我们建议使用 Visual Studio Code 和 Colang 高亮扩展程序 (Github 链接) 来帮助高亮 Colang 代码。
您可以使用 Visual Studio Code 启动设置,在 python 环境中通过按 F5 (launch.json) 运行 Colang 故事。
您可以通过在启动 nemoguardrails 时添加
--verbose
标志来显示生成和接收的事件,这也会显示所有生成的 LLM 提示和响应要查看更多详细信息并显示内部运行时日志,请使用
--debug-level=INFO
或将其设置为DEBUG
日志和打印语句#
为了帮助调试您的 Colang 流,您可以使用 print 语句 print <expression>
将内容打印到标准输出。
flow main
user said something as $flow
print $flow.transcript
> Hi
Hi
或者,使用 log 语句 log <expression>
添加到详细模式下显示的日志中,这将显示为 “Colang Log <flow_instance_uid> :: <expression>”。
此外,Colang 函数 flows_info
可用于返回有关流实例的更多信息
flow main
await a
match RestartEvent()
flow a
$info = flows_info($self.uid)
print pretty_str($info)
{
"flow_instance_uid": "(a)2c62...",
"flow_id": "a",
"loop_id": "(main)8f3d...",
"status": "starting",
"flow_hierarchy": [
"(main)8170..."
],
"active_statement_at_lines": [
6
],
"meta_tags": []
}
其中 pretty_str
将返回的字典对象转换为格式良好的字符串。如果未向该函数提供参数,它将返回一个包含所有当前活动流实例的字典。
CLI 调试命令#
NeMo Guardrail CLI 提供了一些额外的调试命令,这些命令始终以 !
字符开头
> !flows
┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ID ┃ Flow Name ┃ Loop (Priority | Type | Id) ┃ Flow Instances ┃ Source ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ tracking bot talking state │ 10 │ Named │ 'state_tracking' │ 4d0cb,3ea17,b3b49 │ /colang/v2_x/library/core.co │
│ 2 │ tracking user talking state │ 10 │ Named │ 'state_tracking' │ │ /colang/v2_x/library/core.co │
│ 3 │ tracking visual choice selection state │ 10 │ Named │ 'state_tracking' │ fa0f8,196ad │ /colang/v2_x/library/avatars.co │
│ 4 │ _bot_say │ 0 │ parent │ b6036 │ /colang/v2_x/library/core.co │
│ 5 │ _user_said │ 0 │ parent │ 303c3,565f7,cca80 │ /colang/v2_x/library/core.co │
│ 6 │ _user_said_something_unexpected │ 0 │ parent │ 1b5f7,41f02 │ /colang/v2_x/library/core.co │
│ 7 │ _user_saying │ 0 │ parent │ a65e9 │ /colang/v2_x/library/core.co │
│ 8 │ automating intent detection │ 0 │ parent │ c7ead │ /colang/v2_x/library/llm.co │
│ 9 │ await_flow_by_name │ 0 │ parent │ 5f7ef │ /colang/v2_x/library/core.co │
│ 10 │ bot answer question about france │ 0 │ parent │ │ llm_example_flows.co │
│ 11 │ bot ask │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 12 │ bot ask how are you │ 0 │ parent │ │ demo.co │
│ 13 │ bot ask user for age │ 0 │ parent │ │ llm_example_flows.co │
│ 14 │ bot ask user to pick a color │ 0 │ parent │ │ llm_example_flows.co │
│ 15 │ bot asked something │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 16 │ bot asks email address │ 0 │ parent │ │ show_case_back_channelling_interaction.co │
│ 17 │ bot asks user how the day was │ 0 │ parent │ │ show_case_back_channelling_interaction.co │
│ 18 │ bot attract user │ 0 │ parent │ │ llm_example_flows.co │
│ 19 │ bot clarified something │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 20 │ bot clarify │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 21 │ bot count from a number to another number │ 0 │ parent │ │ llm_example_flows.co │
│ 22 │ bot express │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 23 │ bot express feeling bad │ 0 │ parent │ │ demo.co │
│ 24 │ bot express feeling well │ 0 │ parent │ │ demo.co │
│ 25 │ bot express greeting │ 0 │ parent │ │ demo.co │
│ 26 │ bot expressed something │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 27 │ bot gesture │ 0 │ parent │ a2528 │ /colang/v2_x/library/avatars.co │
│ 28 │ bot gesture with delay │ 0 │ parent │ │ /colang/v2_x/library/avatars.co │
│ 29 │ bot inform │ 0 │ parent │ da186 │ /colang/v2_x/library/core.co │
│ 30 │ bot inform about service │ 0 │ parent │ │ demo.co │
│ 31 │ bot informed something │ 0 │ parent │ │ /colang/v2_x/library/core.co │
│ 32 │ bot make long pause │ 0 │ parent │ │ demo.co │
│ 33 │ bot make short pause │ 0 │ parent │ │ demo.co │
└────┴───────────────────────────────────────────┴───┴───────────────────────────┴───────────────────┴───────────────────────────────────────────┴
> !tree
main
├── notification of undefined flow start `Excuse me, what did you say?` (fdb... ,started)
├── notification of colang errors `Excuse me, what did you say?` (69c... ,started)
├── automating intent detection (c7e... ,started)
│ ├── logging marked user intent flows (d84... ,started)
│ └── logging marked bot intent flows (462... ,started)
├── showcase selector (742... ,started)
│ ├── handling bot talking interruption `inform` `stop|cancel` (dea... ,started)
│ │ └── > user interrupted bot talking `15` `stop|cancel` (109... ,started)
│ │ └── > bot started saying something (561... ,started)
│ ├── > user was silent `15.0` (40f... ,started)
│ │ └── > wait `15.0` `wait_timer_1f499f52-9634-4925-b18a-579fef485d5e` (ae4... ,started)
│ ├── > user picked number guessing game showcase (6bc... ,started)
│ │ ├── > user has selected choice `game` (b88... ,started)
│ │ ├── > user said `I want to play the number guessing game` (448... ,started)
│ │ │ └── > _user_said `I want to play the number guessing game` (303... ,started)
│ │ ├── > user said `Show me the game` (d32... ,started)
│ │ │ └── > _user_said `Show me the game` (565... ,started)
│ │ ├── > user said `showcase A` (3fd... ,started)
│ │ │ └── > _user_said `showcase A` (cca... ,started)
│ │ ├── > user said `First showcase` (013... ,started)
│ │ │ └── > _user_said `First showcase` (9d4... ,started)
│ │ └── > user said `re.compile('(?i)guessing game', re.IGNORECASE)` (af9... ,started)
│ │ └── > _user_said `re.compile('(?i)guessing game', re.IGNORECASE)` (966... ,started)
│ ├── > user picked multimodality showcase (e2d... ,started)
│ │ ├── > user has selected choice `multimodality` (f69... ,started)
│ │ ├── > user said `Show me the multimodality showcase` (9be... ,started)
│ │ │ └── > _user_said `Show me the multimodality showcase` (33f... ,started)
│ │ ├── > user said `multimodality` (dfe... ,started)
│ │ │ └── > _user_said `multimodality` (18f... ,started)
│ │ ├── > user said `showcase B` (aa6... ,started)
│ │ │ └── > _user_said `showcase B` (4c5... ,started)
│ │ ├── > user said `Second showcase` (205... ,started)
│ │ │ └── > _user_said `Second showcase` (92a... ,started)
│ │ └── > user said `re.compile('(?i)multimodality', re.IGNORECASE)` (b10... ,started)
│ │ └── > _user_said `re.compile('(?i)multimodality', re.IGNORECASE)` (d86... ,started)
flows [--all] [--order_by_name] # Shows all (active) flows in a table in order of their interaction loop priority and name
tree # Shows the flow hierarchy tree of all (active) flows. A flow is waiting on a child flow to finish if it's indicated by the character `>`.
flow [<flow_name>|<flow_instance_uid>] # Show flow or flow instance details
pause # Pause timer event processing such that interaction does not continue on its own
resume # Resume timer event processing, including the ones trigger during pause
restart # Reset interaction and restart the Colang script
有用的流#
在 Colang 标准库中,有一些有用的流可以帮助 Colang 故事的开发过程
未定义流启动的通知。有时很容易拼错流名称。默认情况下,Colang 只会生成一个 StartFlow(flow_id=<flow 名称>)
内部事件。但是,如果不存在具有该名称的流,则不会发生任何事情。这可能会令人困惑且难以找到。为了获得帮助,您可以激活流 notification of undefined flow start
,它将检测到这些情况,并打印和记录相应的消息,并可以选择让机器人做出响应。
意外用户话语的通知。此流可帮助您检测某些 UtteranceUserAction.Finished()
事件是否未被匹配,因此不会创建机器人响应,这种情况可能几乎永远不会发生。
Colang 错误的通知。当运行 Colang 故事时,可能会由于无效的属性访问或 LLM 相关的解析错误而发生运行时错误。此错误将生成一个 ColangError(error_type: str, error: str)
事件。通常,没有任何内容会匹配此事件,并且机器人将保持沉默。在调试时,这可能会令人困惑,而标准库中的流 notification of colang errors
将通过打印和记录相应的消息并选择让机器人做出响应来帮助使其更加透明。