集成 LUIS 和 QnA 服务时 QnA 服务无响应

No response from QnA service while integrating LUIS and QnA servie

我正在尝试将 LUIS 和 QnA 服务集成到单个机器人中。我使用了 Github 上可用的示例代码来获取对意图的响应。 我尝试使用相同的代码 -

var restify = require('restify');
var builder = require('botbuilder');
var cognitiveservices = require('./node_modules/botbuilder-cognitiveservices/lib/botbuilder-cognitiveservices');
var botbuilder_azure = require("botbuilder-azure");

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: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword,
    openIdMetadata: process.env.BotOpenIdMetadata
});

server.post('/api/messages', connector.listen());

var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);


var bot = new builder.UniversalBot(connector);
//bot.set('storage', new builder.MemoryBotStorage());         // Register in-memory state storage
bot.set('storage', tableStorage);

var luisAppId = process.env.LuisAppId;
 var luisSubscriptionKey = process.env.LuisAPIKey;
 var luisApiHostName = process.env.LuisApiHostName || 'westus.api.cognitive.microsoft.com';
 var luisModelUrl = 'https://' + luisApiHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisSubscriptionKey;

var recognizer = new builder.LuisRecognizer(luisModelUrl);


var qnarecognizer = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: process.env.QnAKnowledgebaseId,
    authKey: process.env.QnAAuthKey,
    });

var intents = new builder.IntentDialog({ recognizers: [recognizer, qnarecognizer] });
bot.dialog('/', intents);

intents.matches('azureBotDevelopment', [
    function (session, args, next) {
        var answerEntity = builder.EntityRecognizer.findEntity(args.entities, 'answer');
        session.send(answerEntity.entity);
    }
]);

intents.onDefault([
    function(session){
        session.send('Sorry!! No match!!');
    }
]);

当我 运行 这个机器人在 Web 聊天时,对于每个问题,它都会回复 Oops. Something went wrong and we need to start over. 在在线编辑器中,出现以下错误 -

Error: QnA request returned a 404 code with body: [object Object]
    at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder-cognitiveservices\lib\QnAMakerRecognizer.js:98:37)
    at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:185:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (D:\home\site\wwwroot\node_modules\request\request.js:1161:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (D:\home\site\wwwroot\node_modules\request\request.js:1083:12)
    at IncomingMessage.g (events.js:291:16)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

我们将不胜感激。

像下面这样组织您的代码应该可行。我使用 Web Chat 和 Emulator 对此进行了测试,结果良好。

本质上,bot.recognizer 就像一个中间件,将返回的 LUIS 意图传递给机器人,并将其与分配了相同值的任何触发器匹配。对于 QnA,将关联的识别器传递到对话中允许在 QnA 知识库中匹配用户输入,随后返回匹配的响应。

var bot = new builder.UniversalBot(connector);
bot.set('storage', new builder.MemoryBotStorage());

var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName  // 'westus.api.cognitive.microsoft.com';

const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisAPIKey;

var luisRecognizer = new builder.LuisRecognizer(LuisModelUrl);

var qnarecognizer = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: process.env.QnAKnowledgebaseId,
    authKey: process.env.QnAAuthKey,
    endpointHostName: process.env.QnAEndpointHostName
});

var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
    recognizers: [qnarecognizer],
    defaultMessage: 'No match! Try changing the query terms!',
    qnaThreshold: 0.3
});

bot.recognizer(luisRecognizer);

bot.dialog('/', basicQnAMakerDialog);

bot.dialog('GreetingDialog',[
    (session) => {
        session.send('You reached the Greeting intent. You said \'%s\'.', session.message.text);
        builder.Prompts.text(session, "What is your name?");
    },
    (session, results) => {
        session.userData.name = results.response;
        session.send("Glad you could make it, " + session.userData.name);
        builder.Prompts.text(session, "Ask me something!");
    },
    (session, results) => {
        session.conversationData.question = results.response;
        session.send(session.conversationData.question + " is an interesting topic!")
        session.endDialog();
    }
]).triggerAction({
    matches: 'Greeting'
})

bot.dialog('HelpDialog',
    (session) => {
        session.send('You reached the Help intent. You said \'%s\'.', session.message.text);
        session.endDialog();
    }
).triggerAction({
    matches: 'Help'
})

你应该知道,到 2019 年 12 月,v3 SDK 将失去支持。届时,将不会通过 Azure 提供新的 v3 机器人。我建议您考虑使用较新的 v4 SDK. You can read more about it the v4 implementation here.

构建您的机器人

希望得到帮助!