Integrating Formflow with Microsoft LUIS

Asked

Viewed 82 times

0

I built a bot using the Microsoft Botbuilder SDK. I want a Botbuilder Formflow to recognize and capture entities in a user response. For example, if the user replies: my email is [email protected], then Formflow would have to capture, as an answer to his question only the email ([email protected]), ignoring the initial part of the text (my email is). Is it possible to do this only with Formflow or do you need to use LUIS to do this? How can LUIS be used together with Formflow?

1 answer

0

Yes, it is possible.

When constructing your Formflow, for all properties of your entity, configure the Field() method of formflow with the validated parameter and call a method that tries to extract all possible entities from LUIS and save in the instance that Formflow is filling.

 .Field(nameof(NomePropriedade), validate: async (state, value) => await ExtractEntity((state as NomeClasse), value, "nomeEntidadeLuisCorrespondenteAoCampoDaVez"))

applying would look like this:

     .Field(nameof(DataNascimento), validate: async (state, value) => await ExtractEntity((state as Cliente), value, "data_nascimento"))

so in every question that Formflow makes you can intercept and extract the entities of luis and send to state.

The Extractentity method would look like this:

 protected static async Task<ValidateResult> ExtractEntity(Cliente state, object value, string entityName, Func<ValidateResult, Task<ValidateResult>> next = null)
    {
        INLPService service = NLPServiceFactory.Create("NomeServicoLuis");
        var nlpresult = await service.QueryAsync(value.ToString());
        var entity = nlpresult.QueryEntity(entityName);
        var result = new ValidateResult { IsValid = true, Value = string.IsNullOrEmpty(entity) ? value : entity };

        var nomeEntity = nlpresult.QueryEntity("nome");
        var dataNascimentoEntity = nlpresult.QueryEntity("data_nascimento");

        state.Nome = CoalesceEntityValue(nomeEntity, entityName, "nome", value.ToString(), state.Nome);
        state.DataNascimento = CoalesceEntityValue(dataNascimentoEntity, entityName, "data_nascimento", value.ToString(), state.DataNascimento);


        if (next != null)
            return await next(result);
        else
            return result;
    }

And finally the Coalesceentityvalue method decides which value to assign in the property, the extracted value of luis, which user typed the current value.

 private static string CoalesceEntityValue(string extractedEntityValue, string extractedEntityName, string entityName, string rawEntityValue, string currentValue)
    {
        if (!string.IsNullOrEmpty(extractedEntityValue))
        {
            return extractedEntityValue;
        }
        else if (!string.IsNullOrEmpty(rawEntityValue) && entityName == extractedEntityName)
        {
            return rawEntityValue;
        }
        else
        {
            return currentValue;
        }
    }

Any doubt I’m available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.