如何在单个Node.js机器人中集成LUIS和QnA Maker服务? [英] How to integrate LUIS and QnA Maker services in single Node.js bot?

查看:88
本文介绍了如何在单个Node.js机器人中集成LUIS和QnA Maker服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Bot Framework和Node.js SDK开发聊天机器人.我已经集成了LUIS和QnA制造商,但如果可能的话,我想创建这种方案.以以下

I'm developing a chatbot using Microsoft Bot Framework with Node.js SDK. I've integrated LUIS and QnA maker but I want to create this scenario if it's possible. Taking in example the following link and in particular this section:

机器人可以通过几种方式实现LUIS和QnA Maker的混合: 首先呼叫LUIS,如果没有意图满足特定阈值分数,即触发无"意图,则呼叫QnA Maker. 或者,为QnA Maker创建一个LUIS意图,向LUIS模型提供映射到"QnAIntent"的示例QnA问题.

There are a few ways that a bot may implement a hybrid of LUIS and QnA Maker: Call LUIS first, and if no intent meets a specific threshold score, i.e., "None" intent is triggered, then call QnA Maker. Alternatively, create a LUIS intent for QnA Maker, feeding your LUIS model with example QnA questions that map to "QnAIntent."

仅举一个例子: 我的QnA KB中有一对:你是谁?" /我是您的机器人!" .然后,我的Luis应用程序将这种意图识别为"common" . 因此,如果我写信给我的机器人:你是谁?" ,它将回答我是你的机器人!" 相反,如果我写告诉我你是谁" ,它会识别与该问题相关的LUIS意图,但不会像我想象的那样回答我是你的机器人!".

Just an example: I have my QnA KB in which I have a pair : " who are you?" / "Hi I'm your bot! " . Then I have my Luis app that recognize this intent called "common" . So, if I write to my bot: " who are you?" it will answer "Hi I'm your bot! " Instead, if I write " tell me who you are" it recognize the LUIS intent related to the question but it will not answer "Hi I'm your bot! " like I imagine.

所以我想像的是:我问一个问题告诉我你是谁"->机器人触发通用意图(LUIS)->然后,我希望机器人能回答我的QnA KB- ->我是您的机器人!"

So what I imagine is: I ask the question "Tell me who you are" --> the bot triggers the intent common (LUIS) --> then I want that the bot will answer me looking into the QnA KB --> "Hi I'm your bot! "

有可能吗?

希望此代码可以帮助您:

Hope this code could help:

var intents = new builder.IntentDialog({ recognizers[luisRecognizer,qnarecognizer] });

bot.dialog('/', intents);

intents.matches('common_question', [
    function (session, args, next) {
        session.send('Intent common');
        qnarecognizer.recognize(session, function (error, result) {
            session.send('answerEntity.entity');
        });
    } 
]);

推荐答案

我之所以这样写,是因为我想对node进行更多的练习,这是使用node的借口,但是Ezequiel告诉你的是完全正确的.我还将在您的GitHub问题上发布.这是一个功能正常的节点应用,可以满足您的需求

I wrote this because I want more practice with node and this was an excuse to use node, but what Ezequiel is telling you is completely correct. I'll also post on your GitHub issue. This is a functioning node app that does what you need

var builder = require('botbuilder');
var restify = require('restify');
var cog = require('botbuilder-cognitiveservices');



var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
    appId: "APP ID",
    appPassword: "APP PASSWORD"
});
server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector, function(session) {
    session.send('Sorry, I did not understand \'%s\'. Type \'help\' if you need assistance.', session.message.text);
});

var recognizer = new builder.LuisRecognizer("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/{LUIS APP ID}?subscription-key={LUIS KEY}&verbose=true&timezoneOffset=0&q=");

bot.recognizer(recognizer);
var qnaRecognizer = new cog.QnAMakerRecognizer({
    knowledgeBaseId: 'QNA APP ID',
    subscriptionKey: 'QNA SUBSCRIPTION KEY'
}); 

bot.dialog('Common', function(session) {
    var query = session.message.text;        
    cog.QnAMakerRecognizer.recognize(query, 'https://westus.api.cognitive.microsoft.com/qnamaker/v2.0/knowledgebases/{QNA APP ID}}/generateAnswer', '{QNA SUBSCRIPTION KEY}', 1, 'intentName', (error, results) => {
        session.send(results.answers[0].answer)    
    })    
}).triggerAction({
    matches: 'Common'
});

这篇关于如何在单个Node.js机器人中集成LUIS和QnA Maker服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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