机器人问答

机器人会提出问题,并从知识库中检索答案。

从 IBM RPA 23.0.3开始,由于除去了 IVR ,因此从此命令中除去了对交互式语音响应 (IVR) 的支持。 有关更多信息,请参阅 已除去

命令可用性: 本地 IBM RPA SaaS 和 IBM RPA

描述

机器人会在聊天中向用户提出问题,并通过使用为聊天主题准备的知识库来识别答案。

要了解有关知识库的更多信息,请参阅知识库

脚本语法

IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。

botAnswerQuestion --kb(String) --evaluate(Boolean) [--version(Numeric)] [--minimumscore(Numeric)] [--topn(Numeric)] [--options(Nullable<AnswerQuestionOptions>)] [--retry(Boolean)] [--attempts(Numeric)] [--retrytext(String)] [--timeoutsub(String)] [--recognitionTimeout(TimeSpan)] [--speechCompleteTimeout(TimeSpan)] [--noInputTimeout(TimeSpan)] [--speechIncompleteTimeout(TimeSpan)] [--confidenceThreshold(Numeric)] [--beep(Boolean)] [--language(Language)] --text(String) [--textformat(String)] [--timeout(TimeSpan)] (String)=utterance (Boolean)=timedout (String)=answer (String)=tags (String)=context (Numeric)=score (List<String>)=options (DataTable)=data (Boolean)=success (String)=botHistoryMessageId

依赖关系

  • 使用 Connect to Chatbot (botConnect) 命令来启动聊天机器人或 IVR 作用域。 Bot ask and Answer 命令必须位于此作用域内。
  • 您必须在租户中发布知识库模型。 有关如何创建知识库模型的更多信息,请参阅 知识库

输入参数

下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。

设计器方式标签 脚本方式名称 必需的 接受的变量类型 描述
知识库 kb Required Text 问答知识库。
版本 version Optional Number 知识库版本。 如果为空,那么将使用租户上知识库的生产版本。
评估 evaluate Optional Boolean 启用以将引用变量替换为赋给它的值。

请参阅 evaluate 参数选项
上下文 (已废弃) context Optional Text 要在问题上查找的答案的上下文。

🛈 注: 此参数已过时。 请改为使用 Context 输出参数。
最低分数 minimumscore Optional Number 问题答案的最低分数。
答案数 topn Optional Number 期望问题的答案数。 问题可以在知识库上定义多个答案。
选项 options Optional AnswerQuestionOptions 从知识库查询答案时使用的选项。

请参阅 options 参数选项
重试 retry Optional Boolean 启用以允许机器人在第一次尝试后没有答案的情况下询问新问题。
尝试次数 attempts Optional Number 机器人尝试提出问题的次数。
重试文本 retrytext Optional Text 第一次尝试但未获得答案时,将向用户询问的备选问题。
子例程 timeoutsub Optional Text 用户响应时间耗尽时运行的子例程。
识别超时 recognitionTimeout Optional Time Span 用于确认用户响应的超时。 如果时间结束,那么会将交互转发到 子例程 参数中指定的子例程。

🛈 请记住: 此参数特定于交互式语音响应 (IVR) 通信。
语音完成超时 speechCompleteTimeout Optional Time Span 不与机器人进行交互所允许的最大时间量。 如果时间结束,那么会将交互转发到在 子例程 参数中指定的子例程。

🛈 请记住: 此参数特定于交互式语音响应 (IVR) 通信。

从 IBM RPA 23.0.3开始,此参数 已除去
启动超时 noInputTimeout Optional Time Span 等待用户开始对话的最大时间量。 如果时间结束,那么会将交互转发到在 子例程 参数中指定的子例程。

🛈 请记住: 此参数特定于交互式语音响应 (IVR) 通信。

从 IBM RPA 23.0.3开始,此参数已 除去
语音未完成超时 speechIncompleteTimeout Optional Time Span 等待用户完成语音的最大时间量。

🛈 请记住: 此参数特定于交互式语音响应 (IVR) 通信。

从 IBM RPA 23.0.3开始,此参数已 除去
置信度 confidenceThreshold Optional Number 用于指示识别用户响应时的置信度级别的数字表达式。

置信度范围在 1-100 之间。 如果获取的值低于指定的范围,那么将返回空值。

从 IBM RPA 23.0.3开始,将 移除此参数。
提示音 beep Optional Boolean 启用以在机器人每次讲话时播放蜂鸣声。

🛈 请记住: 此参数特定于交互式语音响应 (IVR) 通信。

从 IBM RPA 23.0.3开始,此参数 已除去
语言 language Optional Language 用于机器人通信的语言。 使用创建语言 (createLanguage) 命令来获取语言变量。
文本 text Required Text 要回答的问题。
文本格式 textformat Optional Text, BotTextFormat 文本格式。

请参阅 textformat 参数选项
Timeout timeout Optional Time Span, Number, Text 用于等待用户响应的超时。 缺省超时为 5 秒。 使用 Set Timeout (setTimeout) 命令来更改运行时的缺省超时。
如果时间结束, 将交互转发到在 子例程 参数中指定的子例程。

evaluate 参数选项

此参数评估对答案中变量的引用。 对变量的引用是遵循 ${variableName} 模式的任何文本,其中变量将替换为您在脚本上定义的值。

例如,如果知识库包含句子,例如 "要联系我们,请向 ${email}发送电子邮件,或者通过 ${website}访问我们的站点。" , ${email}${website} 都是对当前脚本中变量的引用。

如果启用了此参数,那么用户将看到这些变量以及 emailwebsite 变量在当前脚本中包含的值,例如 contact@example.comwww.example.com

如果此参数处于禁用状态,那么必须使用 Evaluate (evaluate) 命令对变量求值,以便它们可以从各自的变量接收值。

请注意,当您使用 Evaluate 命令时,它将替换对变量值的所有引用。 还会对没有值的变量进行求值。 有关样本用法,请参阅 示例 2

options 参数选项

下表显示了可用于 options 输入参数的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。

设计器方式标签 脚本方式名称 描述
使用同义词 UseSynonyms 检查发送到 KB 的问题中单词的同义词。 可用于 Machine Learning 算法版本 2 的选项。

textformat 参数选项

下表显示了可用于 textformat 输入参数的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。

设计器方式标签 脚本方式名称 描述
Markdown Markdown Markdown 格式。
纯文本 Plain 纯文本格式。

输出参数

设计器方式标签 脚本方式名称 接受的变量类型 描述
话语 utterance Text 返回用户提供的文本。
已超时 timedout Boolean 如果时间结束,那么返回 True ,否则返回 False
答案 answer Text 返回具有最高分数的答案。
标记 tags Text 返回分配给答案的标记 (在知识库中定义)。
上下文 context Text 返回分配给答案的上下文 (在知识库中定义)。
分数 score Number 返回答案的分数。
其他答案 options List<Text> 返回问题的其他答案的列表。
数据 data Data Table 返回一个数据表,其中包含有关问题,答案,上下文,分数和标记的信息。
成功 success Boolean 如果脚本成功运行,那么返回 True ,否则返回 False
历史消息 botHistoryMessageId Text 返回交谈历史记录的标识。
此标识唯一地标识每个 Bot ask 命令的通信片段。 它在上下文中的 Bot ask 命令中生成的数据与从知识库返回的数据之间建立并实施链接,以注册与聊天机器人作用域中的每个通信片段相关的数据。

示例

示例 1: 以下示例演示如何使用知识库来询问和获取聊天机器人中问题的答案。

考虑一个名为 "Chatbot_Sales" 的样本知识库,该知识库支持希望查找其相关信息以处理客户问题的销售人员。 此知识库包含一组有关样本产品的答案和问题。

Bot 询问和回答 命令询问问题,并根据用户的响应,从指定的知识库中分析和检索最佳答案。

🛈 请记住: 以下示例中使用的知识库是一个样本,它表示虚构方案。 您需要先创建知识库并将其发布到租户,然后再使用该知识库。 有关如何创建知识库模型的更多信息,请参阅 知识库

defVar --name answer --type String
defVar --name answerScore --type Numeric
defVar --name culture --type Language
createLanguage --culture "en-US" culture=value
// Connects the chatbot.
botConnect --type "Chat" --language ${culture} --timeout "00:05:00"
	// Ask and answer a question, considering the "Chatbot_Sales" knowledge base, and a minimum score of 500.
	botAnswerQuestion --kb "Chatbot_Sales" --minimumscore 500 --timeoutsub miscommunication --text "Hi! How can I help you?" --textformat "Plain" --timeout "00:01:00" answer=answer answerScore=score
	// Shows the answer on the chat.
	botSay --text "${answer}" --textformat "Plain"
	// Disconnects the chatbot.
botDisconnect
beginSub --name miscommunication
// Shows a message on the chat, if the user don't interact with the chatbot in the time out defined.
	botSay --text "Thank you for contacting us!" --textformat "0"
endSub

示例 2: 以下示例演示如何使用 Evaluate 命令评估对答案中变量的引用。

请考虑 ${email}${telephone}${website} 变量可能作为答案的一部分返回。 在此示例中,会将值分配给这些值,因此可以在需要时使用这些值。

Bot ask and Answer 命令在交谈中发送问题,并且根据样本用户的响应 (例如 "What are the company's contact details?") ,知识库可以返回类似 "To contact us send an email to ${email}, access our site at ${website}, or call us by ${telephone}. Can I assist you with something else?" 的答案。

请注意,它会返回对变量的原始引用,而不是其值,因为 Evaluate 输入参数已关闭。 然后,在 Evaluate 命令之后,您将获得具有赋值的变量值 (如 "To contact us send an email to contact@gmail.com, access our site at www.example.com, or call us by (11) 99999-9999. Can I assist you with something else?") 的答案。

defVar --name answer --type String
defVar --name answerScore --type Numeric
defVar --name culture --type Language
defVar --name email --type String
defVar --name website --type String
defVar --name telephone --type String --value "(11) 99999-9999"
// Creates a Language variable.
createLanguage --culture "en-US" culture=value
// Connects the chatbot.
botConnect --type "Chat" --language ${culture} --timeout "00:05:00"
	// Ask and answer a question. 
	// It doesn't evaluate the expected variables' values in the answer because the Evaluate input parameter is turned off.
	botAnswerQuestion --kb Chatbot_Sales --minimumscore 500 --text "Hi! How can I help you?" --textformat "Plain" --timeout "00:01:00" answer=answer answerScore=score
	// Consider that the KB returns the answer "To contact us send an email to ${email}, access our site at ${website}, or call us by ${telephone}."
	// The following command shows the previous answer on the chat before the Evaluate command.
	botSay --text "Answer before the Evaluate command:\r\n${answer}" --textformat "Plain"
	// Sets a value to the "${email}" variable.
	setVar --name "${email}" --value "contact@gmail.com"
	// Sets a value to the "${telephone}" variable.
	setVar --name "${telephone}" --value "(11) 99999-9999"
	// Sets a value to the "${website}" variable.
	setVar --name "${website}" --value "www.example.com"
	// Evaluate the answer to replace the reference variables to its values.
	evaluate --expression "${answer}" answer=value
	// The following command shows the previous answer on the chat after the Evaluate command. Now the variables' values are assigned to them.
	// For example, "To contact us send an email to contact@gmail.com, access our site at www.example.com, or call us by (11) 99999-9999."
	botSay --text "Answer after the Evaluate command:\r\n${answer}" --textformat "Plain"
	// Disconnects the chatbot.
botDisconnect