Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Bot Framework, LUIS and Action parameters

I am trying to build a bot using LUIS but it is a lot harder than I thought. So far I have managed to create my LUIS application and create an Intent and an Entity and I have created a few Utterances that seem to work fine.

I then created my bot and have hooked it up to Luis. When I test my bot it is working as expected. Now, for the fun part. I want to handle parameters. On Luis I added an action to my Intent:

enter image description here

As you can see I have added a prompt. My code in my bot currently looks like this:

/// <summary>
/// Tries to find the category
/// </summary>
/// <param name="result">The Luis result</param>
/// <param name="alarm"></param>
/// <returns></returns>
public string TryFindCategory(LuisResult result)
{

    // Variable for the title
    EntityRecommendation title;

    // If we find our enenty, return it
    if (result.TryFindEntity(PiiiCK.Category, out title))
        return title.Entity;

    // Default fallback
    return null;
}

[LuisIntent("Choose category")]
public async Task ChooseCategory(IDialogContext context, LuisResult result)
{

    // Get our category
    var category = TryFindCategory(result);
    var response = "The category you have chosen is not in the system just yet.";

    switch (category)
    {
        case "camera":
            response = $"You need help buying a { category }, is this correct?";
            this.started = true;
            break;
        default:
            if (!string.IsNullOrEmpty(category)) response = $"Sorry, PiiiCK does not deal with { category.Pluralise() } just yet.";
            break;
    }

    // Post our response back to the user
    await context.PostAsync(response);

    // Execute the message recieved delegate
    context.Wait(MessageReceived);
}

I think you can guess where I am going with this. If the user types Help me buy a camera, it will get to Choose category Intent and will have the correct Entity selected. But if they type Help me buy, it will still go to the correct Intent, but it will not have a selected Entity. I would like my bot to see that and use the text in the Prompt I created in LUIS and when the user selects their entity I want it to go back to LUIS with that parameter.

I have no idea how to do this and I can't find any tutorials on this. Any help would be appreciated (even links!)

like image 238
r3plica Avatar asked Nov 09 '22 06:11

r3plica


1 Answers

First of all, you need to make sure that in your utterances that contains categories, you are labeling them as the Category entity. This is done by just selecting the word/words that represent your entity and then clicking on the actual category before submitting your utterance.

Labeling utterances

That's independent on the action parameters you added. To check for the action parameters, you need to navigate through the actual intent. The IntentRecommendation has an Actions collection property; which contains a Parameters collection property.

Action parameters

Something to add here, is that in the develop branch, the BotFramework team just added support for LUIS v2 API and added some brand new capabilitites.

For example, now the LuisDialog will act if your intent requires parameters and those are not provided. In that scenario (which it seems is yours), the LuisDialog will automatically launch a LuisActionDialog and ask the user for the missing parameter, using the Prompt message you defined in the action parameter.

Please note that this is not published as Nuget package yet.

like image 118
Ezequiel Jadib Avatar answered Nov 15 '22 06:11

Ezequiel Jadib