我创建了LUIS应用程序,包含1个intent(Order Pizza)和9个实体(Order,Kind,Signature,Size,Toppings,address,Time,Duration,Range)。
我需要在Azure Bot Framework中创建一个bot。我无法理解并使用所有实体的瀑布。请让我知道如何去做它
代码:
dialog.matches('OrderPizza', [
function (session, args, next) {
var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
session.dialogData.intentScore = args.score;
if (!order) {
builder.Prompts.text(session, 'welcome please order pizza');
} else {
session.dialogData.order = order;
next();
}
},
function (session, results) {
var order = session.dialogData.order;
if (results.response) {
session.send('what kind?');
}else{
session.send(`we don't have that kind of pizza`);
}
}
]);
如何进一步推动其他实体?
答案 0 :(得分:1)
我不确定你只能写2个函数是什么意思;但如果你想在对话框中调用LUIS,可以按照example进行操作。您将在session.message.text
的瀑布步骤中调用LuisRecognizer。示例中的代码段如下:
builder.LuisRecognizer.recognize(session.message.text, '<model url>', function (err, intents, entities) {
if (entities) {
var entity = builder.EntityRecognizer.findEntity(entities, 'TYPE');
// do something with entity...
}
});
这样您就可以在瀑布内调用LUIS来识别用户的消息。
关于您的代码,存在许多问题:
// Original Code
dialog.matches('OrderPizza', [
function (session, args, next) {
var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
session.dialogData.intentScore = args.score;
if (!order) { // What about kind?
builder.Prompts.text(session, 'welcome please order pizza');
} else {
session.dialogData.order = order; // What about kind?
next();
}
},
function (session, results) {
var order = session.dialogData.order;
if (results.response) {
session.send('what kind?');
}else{
session.send(`we don't have that kind of pizza`);
}
}
]);
在第一个瀑布步骤中,您没有将"Kind"
实体保存到dialogData。
function (session, args, next) {
var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
session.dialogData.intentScore = args.score;
if (kind) {
session.dialogData.kind = kind;
}
if (!order) {
builder.Prompts.text(session, 'welcome please order pizza');
} else {
session.dialogData.order = order;
next();
}
}
在你的第二个瀑布步骤中,你没有打电话给next
,也没有向用户发送Prompt
,这导致你在两个功能之后被卡住了。
function (session, results, next) {
var order = session.dialogData.order ? session.dialogData.order : results.response;
var kind = session.dialogData.kind;
if (results.response && !kind) {
builder.Prompts.text(session, 'what kind?');
} else {
session.send('we don\'t have that kind of pizza');
next();
}
}