节点-botframework / QnAMaker多个答案

时间:2018-10-23 12:55:38

标签: node.js botframework qnamaker

我如何对同一问题有多个答案?

我使用Node,对此我还很陌生,例如吗?

此线程可以解决我的问题,但是在C#中 How can i use QnAMaker to provide random answers to same query

2 个答案:

答案 0 :(得分:0)

我假设您已经掌握了如何使用botbuilder-cognitive services软件包。

就像在C#版本中一样,您可以覆盖respondFromQnAMakerResult()。您可以在source code中看到您不需要检查是否有任何答案,因为只有在至少有一个答案的情况下才会调用respondFromQnAMakerResult()

这基本上是翻译成JavaScript的另一个问题的解决方案:

basicQnAMakerDialog.respondFromQnAMakerResult = function(session, qnaMakerResult) {
    var msg = qnaMakerResult.answers[0].answer;
    var answersforhowareyou = msg.split('|');

    if (answersforhowareyou.count() > 1)
    {
        var index = Math.floor(Math.random() * answersforhowareyou.length);
        msg = answersforhowareyou[index];
    }

    session.send(msg);
}

答案 1 :(得分:0)

尝试实施此操作,出现以下错误

ReferenceError:答案未定义         在QnAMakerDialog.basicQnAMakerDialog.respondFromQnAMakerResult(D:\ home \ site \ wwwroot \ app.js:123:38)         在QnAMakerDialog.invokeAnswer(D:\ home \ site \ wwwroot \ node_modules \ botbuilder-cognitiveservices \ lib \ QnAMakerDialog.js:76:22)         在D:\ home \ site \ wwwroot \ node_modules \ botbuilder-cognitiveservices \ lib \ QnAMakerDialog.js:52:31         在下一个(D:\ home \ site \ wwwroot \ node_modules \ botbuilder \ lib \ dialogs \ IntentRecognizer.js:68:17)         在IntentRecognizerSet.IntentRecognizer.filter(D:\ home \ site \ wwwroot \ node_modules \ botbuilder \ lib \ dialogs \ IntentRecognizer.js:71:9)         在D:\ home \ site \ wwwroot \ node_modules \ botbuilder \ lib \ dialogs \ IntentRecognizer.js:20:31         在D:\ home \ site \ wwwroot \ node_modules \ botbuilder \ lib \ dialogs \ IntentRecognizerSet.js:80:17         在D:\ home \ site \ wwwroot \ node_modules \ async \ lib \ async.js:52:16         在补充时(D:\ home \ site \ wwwroot \ node_modules \ async \ lib \ async.js:306:28)         在D:\ home \ site \ wwwroot \ node_modules \ async \ lib \ async.js:326:29         在D:\ home \ site \ wwwroot \ node_modules \ async \ lib \ async.js:44:16         在D:\ home \ site \ wwwroot \ node_modules \ botbuilder \ lib \ dialogs \ IntentRecognizerSet.js:72:21         在D:\ home \ site \ wwwroot \ node_modules \ botbuilder-cognitiveservices \ lib \ QnAMakerRecognizer.js:52:21         在Request._callback(D:\ home \ site \ wwwroot \ node_modules \ botbuilder-cognitiveservices \ lib \ QnAMakerRecognizer.js:107:25)         在Request.self.callback(D:\ home \ site \ wwwroot \ node_modules \ request \ request.js:185:22)         在emitTwo(events.js:106:13)