在没有 LUIS 的情况下使用 MS BotFramework NodeJS sdk

Using MS BotFramework NodeJS sdk WITHOUT LUIS

我目前正在做一个项目,访客通常使用英语和中文相互交谈。

由于 LUIS 对多语言的支持不是很好(是的,我知道它可以在某些方面支持,但我想要更好的服务),我想构建自己的神经网络作为 REST API这样,当有人提交他们的文本时,我们可以简单地预测 "Intent",而我们仍在使用 MS BotFramework (NodeJS)。

通过这样做,我们可以绕过 MS LUIS 并使用我们自己的语言理解服务。

这是我的两个问题:

非常感谢您的帮助。

对于 Nodejs botframework 实现,您至少有两种方法:

  1. LuisRecognizer 为起点创建您自己的识别器。这种方法适用于单一意图 NLU 和实体数组(就像 LUIS);
  2. 创建一个 SimpleDialog,其中包含调用所需 NLU 的单个处理函数 API;

除了 Alexandru 的建议之外的另一个选择是添加一个中间件,它会在机器人每次收到 chat/request.

时调用您选择的 NLP 服务

Botbuilder 允许在处理任何对话框之前应用 middleware 函数,我在下面创建了一个示例代码以便更好地理解。

const bot = new builder.UniversalBot(connector, function(session) {
  //pass to root
  session.replaceDialog('root_dialog');
})

//custom middleware
bot.use({
  botbuilder: specialCommandHandler
});

//dummy call NLP service
let callNLP = (text) => {
  return new Promise((resolve, reject) => {
    // do your NLP service API call here and resolve the result

    resolve({});
  });
}

let specialCommandHandler = (session, next) => {
  //user message here
  let userMessage = session.message.text;

  callNLP.then(NLPresult => {
    // you can save your NLP result to a session
    session.conversationData.nlpResult = NLPResult;

    // this will continue to the bot dialog, in this case it will continue to root
    // dialog
    next();
  }).catch(err => {
    //handle errors
  })
}

//root dialog
bot.dialog('root_dialog', [(session, args, next) => {
  // your NLP call result
  let nlpResult = session.conversationData.nlpResult;

  // do any operations with the result here, either redirecting to a new dialog
  // for specific intent/entity, etc.

}]);