1

我正在尝试将该onEnabled方法与 QnAMakerRecognizer 一起使用,这样我就可以拥有多个 QnAMakerRecognizer,并且可以选择启用哪个以及禁用哪个。我已经尝试按照此示例进行操作并尝试了类似的操作,但出现错误消息:

TypeError: (中间值).onEnabled 不是函数

如何onEnable正确使用该方法?

示例代码:

var bot = new builder.UniversalBot(connector);

var qnarecognizer1 = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: knowledgeId, 
    subscriptionKey: subscriptionId,
    qnaThreshold:0.3,
    top:1})
.onEnabled(function (session, callback) {
        // Check to see if this recognizer should be enabled
        if (session.conversationData.useqna1) {
            callback(null, true);
        } else {
            callback(null, false);
        }
    });

var qnarecognizer2 = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: knowledgeId, 
    subscriptionKey: subscriptionId,
    qnaThreshold:0.3,
    top:1})
.onEnabled(function (session, callback) {
        // Check to see if this recognizer should be enabled
        if (session.conversationData.useqna2) {
            callback(null, true);
        } else {
            callback(null, false);
        }
    });

var intentrecognizer = new builder.IntentDialog();

var intents = new builder.IntentDialog({ recognizers: [intentrecognizer, qnarecognizer1, qnarecognizer2] });
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":
                    session.conversationData.useqna1 = true;
        session.conversationData.useqna2 = false;
                    session.send('You can now ask me anything about '+selection+'. Type \'main menu\' anytime to choose a different topic.')
                    session.endConversation();
                    return 

               case "Service2":
                    session.conversationData.useqna1 = false;
        session.conversationData.useqna2 = true;
                    session.send('You can now ask me anything about '+selection+'. Type \'main menu\' anytime to choose a different topic.')
                    session.endConversation();
                    return 

           }
   }

])
4

2 回答 2

1

QnAMakerRecognizer 没有实现 Bot Builder IntentRecognizer,也没有 onEnabled 方法。

https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/dc3517bf651c4209926aa3a9f2a4df0654ab1d5a/Node/lib/QnAMakerRecognizer.js

https://github.com/Microsoft/BotBuilder/blob/070acb410b70312f418d23e032013c4ddf90fdc5/Node/core/lib/dialogs/IntentRecognizer.js

编辑:我已经在 BotBuilder-CognitiveServices repo 上提交了一个问题:https ://github.com/Microsoft/BotBuilder-CognitiveServices/issues/62

于 2017-10-16T22:49:29.117 回答
0

在我们的项目中,我们结束了这样的事情作为一种解决方法。

我们克隆了识别原型函数并检查了会话数据布尔值以启用/禁用识别器。

希望这对你有用 ;)

qnaRecognizer.__proto__['_recognize'] = qnaRecognizer.__proto__['recognize']
qnaRecognizer.__proto__.recognize = function (context, cb) {
  if(!context.conversationData || !context.conversationData.ignoreQnARecognizers){
    return qnaRecognizer.__proto__._recognize.apply(this, [context, cb]);
  } else {
    cb(null, null);
  }
}
于 2018-09-28T22:00:07.620 回答