在一个机器人中使用多个QnA服务

我有多个QnA服务运行,每个都有自己的knowledgeBaseIdsubscriptionKey 。 我想在一个聊天机器中使用它们,我写了一段代码,它接受用户的input并指定正确的知识库细节。 但是,我无法使第二个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 } } ]) 

你永远不会更新QnAMakerRecognizer上的knowledgeId / subscriptionId …这就是你总是看到第一个QnA服务被调用的原因。

看看是否有方法来更新QnAMakerRecognizer这些值。

看看我的回答是否对你的目的是有效的: 一个机器人的多个QnA Maker服务

希望你觉得它有用。