0

我创建了 LUIS 应用程序,具有 1 个意图(订购披萨)和 9 个实体(订购、种类、签名、大小、浇头、地址、时间、持续时间、范围)。

我需要在 Azure Bot Framework 中创建一个机器人。我无法理解和使用所有实体的瀑布。请让我知道如何去做

代码 :

 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`);
   }
 }

    ]);

其他实体如何走得更远?

4

1 回答 1

1

我不确定您只能编写 2 个函数是什么意思;但是,如果您尝试在对话框中调用 LUIS,则可以按照此示例进行操作。您将在您的瀑布步骤中调用 LuisRecognizer session.message.text。示例中的片段如下:

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用户发送 a ,这导致您在两个函数之后被卡住。

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();
  }
}
于 2017-06-14T18:16:37.200 回答