Tinisha Steinman
Tinisha Steinman

Reputation: 1

Using Text Translator to make a Multilingual QnA Bot

I have a QnA bot that I am trying to add bilingual support for. My goal is to use Text translator cognitive service in Azure to identify the user's language based on their initial contact, translate that to english to search the QnA knowledge base and then translate the answer back to the user's language.

The QnA bot is hosted on Azure as a Web Service. I have a beginner level knowledge in programming, and some of the support I have found on the web goes way over my head.

What is the best way to integrate the text translator with the QnA bot?

Upvotes: 0

Views: 692

Answers (1)

Nicolas R
Nicolas R

Reputation: 14609

Your QnA bot is simply a bot which is interacting with QnA Maker API.

So in your case, the easier way of processing is to translate the received message just before querying QnA Maker, then doing the reverse translate on its replies once you got it.

If you have a look to the Bot Builder samples for QnA Maker here, you can see the query, which is using Microsoft.Bot.Builder.AI.QnA:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
    var httpClient = _httpClientFactory.CreateClient();

    var qnaMaker = new QnAMaker(new QnAMakerEndpoint
    {
        KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
        EndpointKey = _configuration["QnAEndpointKey"],
        Host = _configuration["QnAEndpointHostName"]
    },
    null,
    httpClient);

    _logger.LogInformation("Calling QnA Maker");

    // The actual call to the QnA Maker service.
    var response = await qnaMaker.GetAnswersAsync(turnContext);
    if (response != null && response.Length > 0)
    {
        await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken);
    }
    else
    {
        await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
    }
}

As you can see, the call await qnaMaker.GetAnswersAsync(turnContext) is using turnContext directly, not the text itself.

You must modify the Activity text before making this call. Here you can use Translator Text API from Microsoft to do the translation. It can automatically detect input language (but if you already know it, it's better to provide the value).

Then, you have to translate response[0].Answer in the reply.

The reference of Translator API is here: https://learn.microsoft.com/en-us/azure/cognitive-services/translator/reference/v3-0-translate

Note: there is a library which is currently experimental in Bot Builder samples regarding translation: https://github.com/microsoft/BotBuilder-Samples/tree/master/experimental/multilingual-luis/csharp_dotnetcore/Libraries/Microsoft.Bot.Builder.AI.Translation

I did not mentioned it in my reply as I did not had time to check and due to its experimental status.

Upvotes: 2

Related Questions