是的,您可以为您的英语和法语问题分别创建 2 个 QnAMaker 知识库。您可以利用文本分析 API检测机器人中间件中的用户输入语言,该recevie
中间件显示在使用分析确定语言环境中。
请参考以下代码片段:
var recognizer1 = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: <knowledgeBaseId_1>,
subscriptionKey: <subscriptionKey_1>,
top: 4
});
var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
recognizers: [recognizer1],
qnaThreshold: 0.3,
});
var recognizer2 = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: <knowledgeBaseId_2>,
subscriptionKey: <subscriptionKey_2>,
top: 4
});
var basicQnAMakerDialog2 = new cognitiveservices.QnAMakerDialog({
recognizers: [recognizer2],
qnaThreshold: 0.3,
});
bot.dialog('en', basicQnAMakerDialog);
bot.dialog('zh', basicQnAMakerDialog2);
bot.dialog('/', [(session, args) => {
switch (session.preferredLocale()) {
case 'zh':
session.replaceDialog('zh', args)
break;
case 'en-US':
default:
session.replaceDialog('en', args)
break;
}
}])
bot.use({
receive: function (event, next) {
if (event.text) {
var options = {
method: 'POST',
url: 'https://westus2.api.cognitive.microsoft.com/text/analytics/v2.0/languages?numberOfLanguagesToDetect=1',
body: {
documents: [{
id: 'message',
text: event.text
}]
},
json: true,
headers: {
'Ocp-Apim-Subscription-Key': '230f82f08c014accbd067ddc2c0ea98f'
}
};
request(options, function (error, response, body) {
if (!error && body) {
if (body.documents && body.documents.length > 0) {
var languages = body.documents[0].detectedLanguages;
if (languages && languages.length > 0) {
event.textLocale = languages[0].iso6391Name;
}
}
}
next();
});
} else {
next();
}
}
});