【问题标题】:Microsoft Bot Framework LUIS in waterfall conversation瀑布对话中的 Microsoft Bot Framework LUIS
【发布时间】:2017-07-18 07:14:06
【问题描述】:

我有一个现有的瀑布对话。我想对其进行调整,以便它可以从更复杂的用户对机器人问题的响应中提取数据。

在我的 LUIS 应用程序中,我创建了一个名为 GetLocation 的意图,它经过训练可以找到一个名为 Location 的实体。这方面的一个示例是用户键入“我正在寻找布里斯托尔”,这将匹配实体“布里斯托尔”。这是我目前拥有的:

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 来执行此操作?

【问题讨论】:

    标签: node.js bots botframework azure-language-understanding


    【解决方案1】:

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

    对话 1:

    这是您上面的对话框,驱动对话的普通瀑布对话框。

    对话 2:

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

    对话 2 使用 LUIS 解析位置信息并提取实体后,您将结束对话并将实体(位置)返回给对话 1,对话 1 仍将位于 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 意图对话框。

    用户在此之后输入的任何文本都将由您的 LUIS 模型进行解释。这允许您使用您的模型来识别和提取用户的位置信息。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      相关资源
      最近更新 更多