我正在使用 Microsoft 代码示例尝试创建一个使用意图触发 QNA Maker 的 LUIS 机器人。
目前,QnA Maker 有时会返回结果,但有时会返回“TypeError:无法读取未定义的属性 '0'”。
带有以下代码的问题“价格变化”返回来自 QnA 制造商的正确答案。
var customQnAMakerTools = new customQnAMakerTools.CustomQnAMakerTools();
bot.library(customQnAMakerTools.createLibrary());
var intents = new builder.IntentDialog({ recognizers: [recognizer,
r12recognizer] });
bot.dialog('/', intents);
var basicQnAMakerDialog = new builder_cognitiveservices.QnAMakerDialog({
recognizers: [r12recognizer],
defaultMessage: 'Sorry i did not understand that. Try asking the
question again.',
qnaThreshold: 0.3,
feedbackLib: customQnAMakerTools
});
intents.matches('qna', [
basicQnAMakerDialog.respondFromQnAMakerResult = function(session,
qnaMakerResult){
// Save the question
var question = session.message.text;
session.conversationData.userQuestion = question;
// boolean to check if the result is formatted for a card
var isCardFormat = qnaMakerResult.answers[0].answer.includes(';');
if(!isCardFormat){
// Not semi colon delimited, send a normal text response
session.send(qnaMakerResult.answers[0].answer);
}else if(qnaMakerResult.answers && qnaMakerResult.score >= 0.5){
var qnaAnswer = qnaMakerResult.answers[0].answer;
var qnaAnswerData = qnaAnswer.split(';');
var title = qnaAnswerData[0];
var description = qnaAnswerData[1];
var url = qnaAnswerData[2];
var imageURL = qnaAnswerData[3];
var msg = new builder.Message(session)
msg.attachments([
new builder.HeroCard(session)
.title(title)
.subtitle(description)
.images([builder.CardImage.create(session, imageURL)])
.buttons([
builder.CardAction.openUrl(session, url, "Learn More")
])
]);
}
session.send(msg).endDialog();
}
]);
但是,如果我将问题更改为“价格更改已批准但最终被系统拒绝”,这是 QnA Maker 中的完整问题,它会返回“TypeError:无法读取未定义的属性 '0'”。完整的错误是
TypeError: Cannot read property '0' of undefined
at Array.intents.matches.basicQnAMakerDialog.respondFromQnAMakerResult (D:\home\site\wwwroot\app.js:71:46)
at Object.waterfallHandler [as qna] (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:139:29)
at IntentDialog.invokeIntent (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentDialog.js:163:44)
at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentDialog.js:71:27
at next (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:68:17)
at IntentRecognizerSet.IntentRecognizer.filter (D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:71:9)
at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizer.js:20:31
at D:\home\site\wwwroot\node_modules\botbuilder\lib\dialogs\IntentRecognizerSet.js:80:17
at D:\home\site\wwwroot\node_modules\async\lib\async.js:52:16
at replenish (D:\home\site\wwwroot\node_modules\async\lib\async.js:306:28)
如果是因为我错误地传递了问题,或者它只传递了问题的一部分,我目前无法锻炼。