gpt4 book ai didi

node.js - 集成 LUIS 和 QnA 服务时 QnA 服务没有响应

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:21 26 4
gpt4 key购买 nike

我正在尝试将 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!!');
}
]);

当我在网络聊天中运行这个机器人时,对于每个问题,它都会回复哎呀。出了点问题,我们需要重新开始。在在线编辑器中,出现以下错误 -

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)

任何帮助将不胜感激。

最佳答案

像下面这样组织你的代码应该可行。我使用网络聊天和模拟器对此进行了测试,并取得了积极的结果。

本质上,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'
})

您应该注意,v3 SDK 将在 2019 年 12 月失去支持。届时,Azure 将不再提供新的 v3 机器人。我建议您考虑使用较新的 v4 SDK 构建您的机器人。您可以阅读有关 v4 实现的更多信息 here .

希望得到帮助!

关于node.js - 集成 LUIS 和 QnA 服务时 QnA 服务没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56578076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com