Integrating LUIS with FormFlow

2019-04-14 21:26发布

问题:

I have created a bot, having a FormFlow in it. Now if you type I want to launch a product, LUIS will tell which dialog it has to go to :

    internal static IDialog<AssesmentHelper> CreateProduct()
            {
                return Chain.From(() => FormDialog.FromForm(AssesmentHelper.BuildForm))
                    .Do(async (context, profileForm) =>
                    {
                        try
                        {
                            var completed = await profileForm;

                        }
                        catch (FormCanceledException<AssesmentHelper> e)
                        {
                            string reply;
                            if (e.InnerException == null)
                            {
                                reply = $"You quit on {e.Last}--maybe you can finish next time!";
                            }
                            else
                            {
                                reply = Responses.ShortCircuit;
                            }
                            await context.PostAsync(reply);
                        }
                    });
            }

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        { 
stLuis = await LuisHelper.ParseUserInput(activity.Text);
    switch (stLuis.topScoringIntent.intent)
    {

         case "CreateProduct":
              await Conversation.SendAsync(activity, CreateProduct);
              break;

         case "EditProduct":
               await Conversation.SendAsync(activity, EditProduct);
               break;

           case "None":

               break;

            default:
               break;
    }
}

Now, once it enters dialog, it asks user to select numbers:

Please select numbers:

  1. Azure
  2. Windows

Now if I reply 1,2. Luis returns it as None intent, so my message does not go to the corresponding dialog. It always go to None case.

The code for dialog is:

 public static IForm<AssesmentHelper> BuildForm()
        {
            return new FormBuilder<AssesmentHelper>()
                    .Message(Responses.NumberSelection)
                    .Field(nameof(Program))
                    .Field(nameof(Product))
                    .Build();
        }

Enum for program and product:

[Serializable]
    public enum Program
    {
        None = 0,
        A = 1,
     };

        [Serializable]
        public enum Product
        {
            None = 0,
            Azure = 1,
            Windows = 2
        };

As soon as I enter this dialog, It asks me to select number for selecting program. Now if i select 1,2. Luis returns it as None intent. So Case "None", is executed.

What I want is, redirect the control to same dialog. I have similar dialog for Edit Product as well. That's why I cannot train my luis app to understand numbers as Product Intent. Otherwise whenever i select number for Edit Product, it will go to different case.

Earlier it was identifying correct intents somehow, but today i republished my luis app and it stopped identifying.