【问题标题】:How to use Waterfall process in Nodejs using LUIS如何使用 LUIS 在 Nodejs 中使用瀑布过程
【发布时间】:2017-06-14 09:40:48
【问题描述】:

我创建了 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`);
   }
 }

    ]);

如何为其他实体走得更远?

【问题讨论】:

  • 谢谢,我试过了。但是只能写2个函数。之后它没有执行

标签: node.js azure botframework azure-language-understanding azure-bot-service


【解决方案1】:

我不知道你说的只能写 2 个函数是什么意思;但是,如果您尝试在对话框中调用 LUIS,则可以关注此example。您将在 session.message.text 的瀑布步骤中调用 LuisRecognizer。示例中的 sn-p 如下:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2019-10-17
    • 1970-01-01
    • 2014-10-31
    相关资源
    最近更新 更多