r3plica r3plica - 22 days ago 19
C# Question

Microsoft Bot Framework with LUIS

Man am I having issue with this.
I am trying to create a simple bot with the help of Luis.
I have managed to create a bot and host it on azure, I have also created an intent in LUIS and an entity. I have created some utterances and that side is working fine.

I then created by LuisDialog in c#. I had to create Cognitive Services API subscription in Azure and I copied to 2 keys it had generated into my LuisDialog.

My Dialog looks like this:

/// <summary>
/// Entities for the PiiiCK LUIS model.
/// </summary>
public static partial class PiiiCK
{
public const string DefaultCategory = "none";
public const string ChooseCategoryIntent = "Choose category";
}

[Serializable]
public class PiiiCKLuisDialog : LuisDialog<object>
{

/// <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.ChooseCategoryIntent, out title))
return title.Entity;

// Default fallback
return PiiiCK.DefaultCategory;
}

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

// Create our response
var response = $"Sorry I did not understand";

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

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

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

// Get our category
var category = TryFindCategory(result);

// Create our response
var response = $"Found our entity: { category }";

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

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


When I run the project and use the Bot emulator to get my responses it always hits none. Even if I write a message exactly the same as the utterance. Now I assume it is because I have confused myself. I believe there is another step after getting the keys from by Cognitive Service account to link it to LUIS endpoint, does anyone know what I am supposed to do next?




Update



I was using the Alarm bot example to create my bot, but it was confusing me (mainly because I have never used Autofac before), so I have switched to the Simple Alarm bot example instead.
The changes I need to make was with Global.asax:

protected void Application_Start() => GlobalConfiguration.Configure(WebApiConfig.Register);


And add the LuisModel Data Annotation to the PiiiCKLuisDialog like so:

[Serializable]
[LuisModel("The Luis App Id", "The microsoft cognitive services subscription key")]
public class PiiiCKLuisDialog : LuisDialog<object>


When I run my application, I get no errors and when I use my Microsoft Bot Emulator with the MicrosoftAppId and Secret I can type a message, but it still does the same as before. It always goes to the None Luis Intent and never to the "Choose category" one.
It is worth noting that the LuisResult is always null...

Any ideas?

K48 K48
Answer

You don't need to copy two keys.

You need to only use any one of the two keys as the second argument to LuisModel. For the first argument, use the app ID that looks like a GUID and can be found on LUIS.ai.

Update:

1) Here is what you use as the first parameter to [LuisModel("","")] - that's your LUIS app ID:

enter image description here

2) As the second parameter, you use any of the two keys you got from Azure portal or Cognitive Services account. Doesn't matter which of the two.

Finally, you can always test your endpoint and see both input params from your account at luis.ai. Click "Publish", enter anything into "query", then press Enter. You will see the params in the URL.

enter image description here