瀑布对话中的Microsoft Bot Framework LUIS [英] Microsoft Bot Framework LUIS in waterfall conversation

查看:72
本文介绍了瀑布对话中的Microsoft Bot Framework LUIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的瀑布对话.我想对其进行修改,以便它可以从更复杂的用户对机器人问题的回答中提取数据.

I have an existing waterfall conversation. I want to adapt it so that it can extract data from more complex user responses to the bot's questions.

在我的LUIS应用程序中,我创建了一个名为GetLocation的意图,该意图被训练为找到一个名为Location的实体.例如,用户键入我正在布里斯托尔看",这将与实体布里斯托尔"匹配.这是我目前拥有的:

In my LUIS app I have created an intent called GetLocation which is trained to find an entity called Location. An example of this is the user typing "I am looking in Bristol" which would match the entity "Bristol". This is what I currently have:

function(session) {
       builder.Prompts.text(session, "Hello... Which city are you looking    in?");
},
function(session, results) {
    session.privateConversationData.city = results.response;
    builder.Prompts.number(session, "Ok, you are looking in " + results.response + ", How many bedrooms are you looking for?");
},
etc...

我不想简单地存储响应字符串,而是将响应字符串发送给LUIS并从中提取城市位置.我发现的所有LUIS示例都用于匹配并转到新的Intent,但是我只是想保持瀑布式对话的进行.我将如何利用LUIS做到这一点?

Instead of simply storing the response string, I want to send the response string off to LUIS and extract the city location from it. All of the LUIS examples I've found are for matching and going to new Intents however I simply want to keep the waterfall conversation going. How would I utilise LUIS to do this?

推荐答案

我认为您可以通过设置两个不同的对话框来做到这一点:

I think you can do this by having two different dialogs setup:

对话框1:

这是您上面的对话框,是推动对话的常规瀑布"对话框.

This is the dialog you have above, your normal Waterfall dialog that drives the conversation.

对话框2:

将使用您的LUIS模型使用LUIS Intent识别器创建此对话框.对话框1将发出提示,然后将用户转到该对话框并解析用户输入的文本.由于您的模型已经过识别位置的训练,因此您现在要做的就是提取实体.

This dialog will be created with a LUIS Intent recognizer using your LUIS model. Dialog 1 will issue the prompt, then pass the user to this dialog and parse the text entered by the user. Since your Model is already trained to recognize location, all you need to do now is extract the entity.

对话框2使用LUIS解析位置信息并提取实体后,您将结束对话框并将实体(位置)返回到对话框1,该对话框仍位于

After dialog 2 has parsed the location information using LUIS, and extracted the entity, you will end the dialog and return the entity (location) back to dialog 1, which will still be on the Dialog Stack.

代码

//create intent recognizer based on LUIS model
var luisModel = "<Your LUIS Model URL>";
var recognizer = new botbuilder.LuisRecognizer(luisModel);
//create dialog handler for info to be parsed by LUIS
var dialog = new botbuilder.IntentDialog({ recognizers: [recognizer] });

//root dialog
bot.dialog("/", [
    function(session){

        //prompt user and pop LUIS intent dialog onto dialog stack
        session.send("Hello, which city are you looking in?");
        session.beginDialog("/begin_loc_parse");

    },

    //this will be resumed after our location has been extracted
    function(session, results){

        //check for extracted location
        if(results.entity){
            //got location successfully
            session.send("Got city from user: " + results.entity);

            //resume normal waterfall with location.....

        } else {
            //start over
            session.beginDialog("/");
        }
    }
]);

//LUIS intent dialog
dialog.matches("input_location", function(session, args){

    //grab location entity
    var city = botbuilder.EntityRecognizer.findEntity(args.entities, "builtin.geography.city");

    if(city){
        //pop the LUIS dialog off of the dialog stack
        //and return the extracted location back to waterfall
        session.endDialogWithResult(city);
    } else session.endDialog("Couldn't extract city entity.");

});

//called if user doesn't enter something like "I am looking in [city]"
dialog.onDefault(function(session, args){
    session.send("I'm sorry, I didn't quite catch that. In which city are you looking?");
});


因此,基本上,在根对话框中,当提示用户输入位置,然后调用session.beginDialog("/begin_loc_parse")时,您已将对话传递到LUIS意向对话框.


So basically, in the root dialog, when you prompt the user for the location, and then call session.beginDialog("/begin_loc_parse") you will have passed the conversation to your LUIS intent dialog.

此后,用户输入的任何文本将由您的LUIS模型解释.这使您可以使用模型来识别和提取用户的位置信息.

Any text entered by the user after this point will be interpreted by your LUIS model. This allows you to use your model to recognize and extract the location information from the user.

然后,关键是使用session.endDialogWithResult()从堆栈中弹出LUIS对话框,并使用新提取的位置返回到原始瀑布.

Then, the key is to use session.endDialogWithResult()to pop the LUIS dialog off the stack, and to go back to your original waterfall with your newly extracted location.

这篇关于瀑布对话中的Microsoft Bot Framework LUIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆