gpt4 book ai didi

node.js - 将 onEnabled 方法与 QnAMakerRecognizer 结合使用

转载 作者:太空宇宙 更新时间:2023-11-04 00:16:35 25 4
gpt4 key购买 nike

我尝试将 onEnabled 方法与 QnAMakerRecognizer 一起使用,以便我可以拥有多个 QnAMakerRecognizer,并可以选择启用和禁用哪些。我尝试遵循此example并尝试了类似的方法,但我收到一条错误消息:

TypeError: (intermediate value).onEnabled is not a function

如何正确使用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

}
}

])

最佳答案

关于node.js - 将 onEnabled 方法与 QnAMakerRecognizer 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46688548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com