1
votes

I want my bot to support German language. So, I have created a seperate model for German language with the same intents and entities as in the English model. How can I select specific model on the run time based on user language. Apparently, I can ask user to choose their language preference, save that in Bot Databag and then set the culture "en" or "de" based on that. But, how can I select German/English model on run time? I have following Luis model with both German and English model keys as attribute. P.S. I have read other related posts and they are about two models with different intent and entities. I have two models with different locale.

[LuisModel("LuisID", "English Model-Key")]
[LuisModel("LuisID", "German Model-Key")]
[Serializable]
public class LUISDialogClass : LuisDialog<object>
{
    public LUISDialogClass(params ILuisService[] services) : base(services)
        {

        }
    [LuisIntent("A")]
    public async Task A(IDialogContext context, LuisResult result)
    {

    }
    [LuisIntent("B")]
    public async Task B(IDialogContext context, LuisResult result)
    {

    }
}
1
but the utterance of each luis app are in a different language right? So, it should automatucally handled or that's not what you are seeing? LUIS models will return the specific intent.. and then it will be a matter of scoring, an utterance in english will likely score more than the one in germanEzequiel Jadib
@EzequielJadib , Yes utterences are in different language. So, the Luis dialog will send request to both apps and get response and one of them will be charged for no reson? I want to send request to only one app based on the locale. Also I do not want to add multiple luis dialogs for each language in my code.Ehsan Ul Haq
@EhsanUlHaq you create an abstract superclass with all logic present, and each subclass extends it and adds the desired Luis creds in the Luis Annotation. Busy right now. But I will complete the answer later.Rinor
@rinormaloku , Sure, Looking forward. ThanksEhsan Ul Haq

1 Answers

4
votes

There are two solutions:

  1. Control Rest calls to LUIS yourself.
  2. Create two dialogs LUISDialogClassDe and LUISDialogClassUs.

Elaborating the second solution:

a) Implement all the logic in the abstract class:

[Serializable]
public abstract class LUISDialogClass : LuisDialog<object>
{
    public LUISDialogClass(params ILuisService[] services) : base(services)
    {

    }

    [LuisIntent("A")]
    public async Task A(IDialogContext context, LuisResult result)
    {

    }

    [LuisIntent("B")]
    public async Task B(IDialogContext context, LuisResult result)
    {

    }
}

b) Create a concrete class that extends the abstract class with the sole purpose of providing Luis credentials.

[Serializable]
[LuisModel("key_DE", "programmatic_key_DE")]
public class LUISDialogClassDe : LUISDialogClass
{
}

c) Repeat as often as you need.

[Serializable]
[LuisModel("key_US", "programmatic_key_US")]
public class LUISDialogClassUs : LUISDialogClass
{
}

d) Use it in your code as follows:

var state = activity.GetStateClient();
var userdata = state.BotState.GetUserData(activity.ChannelId, activity.From.Id);
var cultureInfo = userdata.GetProperty<CultureInfo>("lang");

if (cultureInfo.Equals(new CultureInfo("de-DE")))
{
    await Conversation.SendAsync(activity, () => new LUISDialogClassDe());
}
else
{
    await Conversation.SendAsync(activity, () => new LUISDialogClassUs());
}