0

We have a chatbot and a button beside it which can change the language of bot between English and French. I also have a QnAmaker contains both English and French questions. Is there a way for us to only handle English questions when bot is at English mode? Same goes to French.

Note: my bot react like this:
    user: what is teww?
                       Do you mean this, select one of question below: BOT
                         1. French question
                         2. English question
                         3  French question

I want prevent this from happening, I am thinking about creating two qnamaker one for french one for english. however I don't know to handle this qna changes in the azure bot service? is there a way to work around it?

Platform: Azure Bot Service Node.JS Microsoft QnA Maker

  • Documentation from https://qnamaker.ai/Documentation/Faqs clearly states "If you have content from multiple languages, be sure to create a separate service for each language." each service has different ids, so you will have one dialog per language – Simon Mourier Apr 06 '18 at 21:02

1 Answers1

3

Yes, you can create 2 QnAMaker knowledge bases individual for your English and French questions. And you can leverage Text Analytics API to detect user input language in bot's recevie middleware which shows at Determine the locale by using analytics.

Please refer to the following code snippet:

var recognizer1 = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: <knowledgeBaseId_1>,
    subscriptionKey: <subscriptionKey_1>,
    top: 4
});

var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
    recognizers: [recognizer1],
    qnaThreshold: 0.3,
});
var recognizer2 = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: <knowledgeBaseId_2>,
    subscriptionKey: <subscriptionKey_2>,
    top: 4
});

var basicQnAMakerDialog2 = new cognitiveservices.QnAMakerDialog({
    recognizers: [recognizer2],
    qnaThreshold: 0.3,
});

bot.dialog('en', basicQnAMakerDialog);
bot.dialog('zh', basicQnAMakerDialog2);

bot.dialog('/', [(session, args) => {
    switch (session.preferredLocale()) {
        case 'zh':
            session.replaceDialog('zh', args)
            break;
        case 'en-US':
        default:
            session.replaceDialog('en', args)
            break;
    }
}])

bot.use({
    receive: function (event, next) {
        if (event.text) {
            var options = {
                method: 'POST',
                url: 'https://westus2.api.cognitive.microsoft.com/text/analytics/v2.0/languages?numberOfLanguagesToDetect=1',
                body: {
                    documents: [{
                        id: 'message',
                        text: event.text
                    }]
                },
                json: true,
                headers: {
                    'Ocp-Apim-Subscription-Key': '230f82f08c014accbd067ddc2c0ea98f'
                }
            };
            request(options, function (error, response, body) {
                if (!error && body) {
                    if (body.documents && body.documents.length > 0) {
                        var languages = body.documents[0].detectedLanguages;
                        if (languages && languages.length > 0) {
                            event.textLocale = languages[0].iso6391Name;
                        }
                    }
                }
                next();
            });
        } else {
            next();
        }
    }
});
Gary Liu
  • 13,758
  • 1
  • 17
  • 32