基本核心流程 (core.co)#
包含与用户和机器人话语事件和操作相关的所有相关流程的核心库。
用户事件流程#
- user said $text -> $transcript
等待用户使用完全匹配说出提供的文本。
示例
import core flow main # Only matches exactly "hello" user said "hello" bot say "hi"
> hi > hello hi
- user said something -> $transcript
等待用户说出与任何脚本匹配的内容。
示例
import core flow main $transcript = await user said something bot say "You said: {$transcript}"
> I can say whatever I want You said: I can say whatever I want
- user saying $text -> $transcript
等待用户在说话时说出给定的文本(即使话语尚未完成,这也匹配用户话语的部分脚本)。
示例
import core flow main # Provide verbal feedback while the user is writing / speaking while True when user saying "sad" bot say "oooh" or when user saying "great" bot say "nice!"
> /UtteranceUserAction.TranscriptUpdated(interim_transcript="this is a ") > /UtteranceUserAction.TranscriptUpdated(interim_transcript="this is a sad story") oooh > /UtteranceUserAction.TranscriptUpdated(interim_transcript="this is a sad story that has a great ending") nice!
- user saying something -> $transcript
等待任何正在进行的用户话语(部分脚本)。
示例
import core import avatars flow main user saying something bot gesture "nod"
> /UtteranceUserAction.TranscriptUpdated(interim_transcript="anything") Gesture: nod
- user started saying something
等待用户话语开始
示例
import core import avatars flow main # Start a bot posture as soon as the user starts talking user started saying something start bot posture "listening" as $ref # Stop the posture when the user is done talking user said something send $ref.Stop()
> /UtteranceUserAction.Started() Posture: listening > /UtteranceUserAction.TranscriptUpdated(interim_transcript="I am starting to talk") > /UtteranceUserAction.Finished(final_transcript="anything") bot posture (stop)
- user said something unexpected -> $transcript
等待用户说出一些意外的内容(没有与传入事件匹配的用户话语的活动匹配语句)。这是一个相当技术性的流程。如果您正在寻找一种方法来响应各种用户消息,请查看
llm.co
中的流程。示例
import core flow handling welcome user said "hi" or user said "hello" bot say "hello" flow main activate handling welcome # If the user utterance is anything else except "hi" and "hello" this will advance user said something unexpected bot say "you said something unexpected"
> hi hello > how are you you said something unexpected
机器人操作流程#
- bot say $text
使用提供的文本执行机器人话语,并等待直到话语完成(例如,对于语音机器人,此流程将在机器人音频完成后完成)。
示例
import core flow main user said something bot say "Hello world!"
> anything Hello world!
语义变体
为了更具表现力的交互历史记录和更高级的用例,
core.co
库为bot say
提供了几个语义包装器。您可以在任何地方使用它们代替bot say
来注释机器人话语的目的。# Trigger the bot to inform about something flow bot inform $text # Trigger the bot to ask something flow bot ask $text # Trigger the bot to express something flow bot express $text # Trigger the bot to respond with given text flow bot respond $text # Trigger the bot to clarify something flow bot clarify $text # Trigger the bot to suggest something flow bot suggest $text
机器人事件流程#
- bot started saying $text
等待机器人开始给定的说话
示例
import core flow reacting to bot utterances bot started saying "hi" send CustomEvent() flow main activate reacting to bot utterances user said something bot say "hi"
> hello hi Event: CustomEvent
- bot started saying something
等待机器人开始任何说话
示例
import core import avatars flow handling talking posture bot started saying something bot posture "talking" bot said something flow main activate handling talking posture user said something bot say "hi"
> something hi Posture: talking bot posture (stop)
- bot said $text
等待机器人说完给定的说话
示例
import core import avatars flow creating gestures when bot said "yes" bot gesture "thumbs up" or when bot said "no" bot gesture "shake head" flow answering cat dog questions when user said "Do you like cats?" bot say "yes" or when user said "Do you like dogs?" bot say "no" flow main activate creating gestures activate answering cat dog questions wait indefinitely
> Do you like cats? yes Gesture: thumbs up > Do you like dogs? no Gesture: shake head
- bot said something -> $text
等待机器人完成任何说话
示例
import core import avatars flow handling talking posture bot started saying something bot posture "talking" bot said something flow main activate handling talking posture user said something bot say "hi"
> something hi Posture: talking bot posture (stop)
语义变体
您可以对
core.co
库中定义的bot say
的特定语义包装器做出反应# Wait for the bot to finish informing about something flow bot informed something -> $text # Wait for the bot to finish asking about something flow bot asked something -> $text # Wait for the bot to finish expressing something flow bot expressed something -> $text # Wait for the bot to finish responding something flow bot responded something -> $text # Wait for the bot to finish clarifying something flow bot clarified something -> $text # Wait for the bot to finish suggesting something flow bot suggested something -> $text
实用程序#
- wait indefinitely
无限期等待的辅助流程。这通常在
main
流程的末尾使用,以确保交互不会重新启动。示例
import core flow main bot say "hello" wait indefinitely
> hello
状态跟踪流程#
这些是在全局变量中跟踪机器人和用户状态的流程。
- tracking bot talking state
在全局变量
$bot_talking_state
,$last_bot_script
中跟踪机器人说话状态。示例
import core flow main global $bot_talking_state activate tracking bot talking state user said something if $bot_talking_state bot gesture "show ignorance to user speech" else bot say "responding to user question"
> hello there responding to user question
- tracking user talking state
在全局变量中跟踪用户话语状态:
$user_talking_state
,$last_user_transcript
。示例
import core flow main global $last_user_transcript activate tracking user talking state user said something bot say "I remembered {$last_user_transcript}"
> my favorite color is red I remembered my favorite color is red
开发助手流程#
- notification of colang errors
一个用于通知任何运行时 Colang 错误的流程
示例
import core # We need to create an artificial error. # We need to create this in a separate flow as otherwise the main flow will fail upon the error. flow creating an error user said something $number = 3 print $number.error flow main activate notification of colang errors creating an error wait indefinitely
> test Excuse me, there was an internal Colang error.
- notification of undefined flow start
一个用于通知未定义流程开始的流程
示例
import core flow main activate notification of undefined flow start # We are misspelling the `bot say` flow to trigger a undefined flow start. user said something bot sayy "hello"
> test Failed to start an undefined flow!
- notification of unexpected user utterance
一个用于通知未处理的用户话语的流程
示例
import core flow reacting to user requests user said "hi" or user said "hello" bot say "hi there" flow main activate notification of unexpected user utterance activate reacting to user requests
> hello hi there > what is your name I don't know how to respond to that!