如何在使用LUIS的Nodejs中使用瀑布进程

问题描述:

我有1个意图(Order Pizza)和9个实体(Order,Kind,Signature,Size,浇头,地址,时间,持续时间,范围)创建了LUIS应用程序。如何在使用LUIS的Nodejs中使用瀑布进程

我需要在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

尝试[文档](https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-dialog-manage-conversation) – stuartd

+0

谢谢,我试图。但只能写2个函数。之后它不执行 – Anagha

我不确定你的意思是只能写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(); 
    } 
}