在 Waterfall-Dialog 中移动数据。机器人框架SDK
Move data in Waterfall-Dialog. Bot Framework SDK
我正在使用 Bot Framework SDK 和 nodejs 来实现消歧流程。
我想如果 Luis 预测的两个意图彼此接近,询问用户他们想要哪一个。我已经完成了验证程序,但是流程有问题。
这是一个包含 3 个步骤的瀑布对话框:
- 第一步:调用 Orchestrator 和 Luis 以获取意图和实体。它通过
return await step.next({...})
传递数据
- 消歧步骤:检查是否需要消歧,如果出现歧义,提示选项。如果没有,它像第一步一样传递数据。
- 回答步骤:如果在
step.result
中收到的数据中有消歧标志,它会根据用户响应提示回答。在其他地方,它使用来自第一步的 step.result
中的数据。
问题是,当它提示用户说出意图时,我丢失了 FirstStep 的数据,因为我无法使用 step.next({...})
¿如何维护第一步的数据和用户在提示中的回答?
基本代码如下:
async firstStep(step) {
logger.info(`FinalAnswer Dialog: firstStep`);
let model_dispatch = await this.bot.get_intent_dispatch(step.context);
let result = await this.bot.dispatchToTopIntentAsync(step.context, model_dispatch.model)
// model_dispatch = orchestrator_model
// result = {topIntent: String, entities: Array, disamibiguation: Array}
return await step.next({ model_dispatch: model_dispatch, result: result})
}
async disambiguationStep(step) {
logger.info(`FinalAnswer Dialog: disambiguationStep`);
if (step.result.result.disambiguation) {
logger.info("We need to disambiguate")
let disambiguation_options = step.result.result.disambiguation
const message_text = "What do you need";
const data = [
{
"title": "TEXT",
"value": disambiguation_option[0]
},
{
"title": "TEXT",
"value": disambiguation_option[1]
},
]
let buttons = data.map(function (d) {
return {
type: ActionTypes.PostBack,
title: d.title,
value: d.value
}
});
const msg = MessageFactory.suggestedActions(buttons, message_text);
return await step.prompt(TEXT_PROMPT, { prompt: msg });
return step.next(step.result) //not working
}
else {
logger.info("We dont desambiguate")
return step.next(step.result)
}
}
async answerStep(step) {
logger.info(`FinalAnswer Dialog: answerStep`);
let model_dispatch = step.result.model_dispatch
let result = step.result.result
//Show answer
return await step.endDialog();
}
您可以使用步骤字典来存储您的值。 GitHub 上的复杂对话示例非常适合演示这一点。 https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js
我正在使用 Bot Framework SDK 和 nodejs 来实现消歧流程。
我想如果 Luis 预测的两个意图彼此接近,询问用户他们想要哪一个。我已经完成了验证程序,但是流程有问题。
这是一个包含 3 个步骤的瀑布对话框:
- 第一步:调用 Orchestrator 和 Luis 以获取意图和实体。它通过
return await step.next({...})
传递数据
- 消歧步骤:检查是否需要消歧,如果出现歧义,提示选项。如果没有,它像第一步一样传递数据。
- 回答步骤:如果在
step.result
中收到的数据中有消歧标志,它会根据用户响应提示回答。在其他地方,它使用来自第一步的step.result
中的数据。
问题是,当它提示用户说出意图时,我丢失了 FirstStep 的数据,因为我无法使用 step.next({...})
¿如何维护第一步的数据和用户在提示中的回答?
基本代码如下:
async firstStep(step) {
logger.info(`FinalAnswer Dialog: firstStep`);
let model_dispatch = await this.bot.get_intent_dispatch(step.context);
let result = await this.bot.dispatchToTopIntentAsync(step.context, model_dispatch.model)
// model_dispatch = orchestrator_model
// result = {topIntent: String, entities: Array, disamibiguation: Array}
return await step.next({ model_dispatch: model_dispatch, result: result})
}
async disambiguationStep(step) {
logger.info(`FinalAnswer Dialog: disambiguationStep`);
if (step.result.result.disambiguation) {
logger.info("We need to disambiguate")
let disambiguation_options = step.result.result.disambiguation
const message_text = "What do you need";
const data = [
{
"title": "TEXT",
"value": disambiguation_option[0]
},
{
"title": "TEXT",
"value": disambiguation_option[1]
},
]
let buttons = data.map(function (d) {
return {
type: ActionTypes.PostBack,
title: d.title,
value: d.value
}
});
const msg = MessageFactory.suggestedActions(buttons, message_text);
return await step.prompt(TEXT_PROMPT, { prompt: msg });
return step.next(step.result) //not working
}
else {
logger.info("We dont desambiguate")
return step.next(step.result)
}
}
async answerStep(step) {
logger.info(`FinalAnswer Dialog: answerStep`);
let model_dispatch = step.result.model_dispatch
let result = step.result.result
//Show answer
return await step.endDialog();
}
您可以使用步骤字典来存储您的值。 GitHub 上的复杂对话示例非常适合演示这一点。 https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js