我有多个QnA服务正在运行,每个服务都有自己的knowledgeBaseId
和subscriptionKey
。我想在一个聊天机器人中使用它们,我写了一段代码,它接受用户输入并分配正确的知识库详细信息。但是,我无法让第二个QnA服务变为活动状态,并且机器人仅链接到第一个服务。这可能会出现什么问题?
示例代码:
var knowledgeId = "FIRST_QNA_SERVICE_KNOWLEDGE_ID";
var subscriptionId = "FIRST_QNA_SERVICE_SUBSCRIPTION_ID";
var bot = new builder.UniversalBot(connector);
var qnarecognizer = new cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: knowledgeId,
subscriptionKey: subscriptionId,
qnaThreshold:0.3,
top:1});
var intentrecognizer = new builder.IntentDialog();
var intents = new builder.IntentDialog({ recognizers: [intentrecognizer, qnarecognizer] });
bot.dialog('/', intents);
intents.matches('qna', [
function (session, args, next) {
args.entities.forEach(function(element) {
session.send(element.entity);
}, this);
}
]);
intents.matchesAny([/hi/i, /main menu/i], [
function (session) {
builder.Prompts.choice(session, "Hi, What would you like to ask me about?", ["Service1","Service2"],{ listStyle: builder.ListStyle.button});
},
function (session, result) {
var selection = result.response.entity;
switch (selection) {
case "Service1":
knowledgeId = "FIRST_QNA_SERVICE_KNOWLEDGE_ID";
subscriptionId = "FIRST_QNA_SERVICE_SUBSCRIPTION_ID";
session.send('You can now ask me anything about '+selection+'. Type \'main menu\' anytime to choose a different topic.')
session.endConversation();
return
case "Service2":
knowledgeId = "SECOND_QNA_SERVICE_KNOWLEDGE_ID";
subscriptionId = "SECOND_QNA_SERVICE_SUBSCRIPTION_ID";
session.send('You can now ask me anything about '+selection+'. Type \'main menu\' anytime to choose a different topic.')
session.endConversation();
return
}
}
])
答案 0 :(得分:0)
您从未更新QnAMakerRecognizer上的knowledgeId
/ subscriptionId
...这就是您始终看到第一个QnA服务被调用的原因。
查看是否有办法更新QnAMakerRecognizer
中的这些值。
答案 1 :(得分:0)
在此问题上查看我的回答是否符合您的目的: Multiple QnA Maker services for a single bot
希望你觉得它很有用。