在意向中提示用户缺少实体,并等待他们响应



我一直在尝试解决这个问题,我想这可能很容易,但我还找不到实现它的方法。

我有一个非常简单的路易斯意图如下:

[LuisIntent("xxx")]
public async Task xxx(IDialogContext context, LuisResult result)
{
var entities = new List<EntityRecommendation>(result.Entities);
//do stuff eg. Prompt.Text(contenxt, "Enter your name");
//await prompt
//store new response into the variable
}

我想要实现的是提示用户在其查询中输入任何缺少的实体,并将其保存以供以后在此意图中使用。问题是意图不等待用户响应,只是像往常一样继续执行。

我错过了什么?

提前谢谢。

您需要调用一个新对话框来提示输入其余实体。 我会使用基于您尝试捕获的所有实体的 FormFlow 对话框。基本上,你希望假设没有实体通过 Luis 意向,这样就可以提示用户输入所有内容。 因此,使用FormFlow,您可以指定FromFlow的初始状态。为此,请创建一个实例,并使用您收到的实体填写属性。FormFlow 将跳过已填充的任何字段的步骤。 或者,当您启动 FormDialog 时,您可以传入"FormOptions.PromptFieldsWithValues"。这将告诉对话框仍提示用户输入所有值,但将使用填充的值作为默认值。如果要为用户提供更改某些内容的选项,则可以执行此操作。

这是我从github中提取的一个基本示例。

这是定义状态的类。您将根据要接收的实体构建此内容

public class SampleQuestion
{
public string FavoriteColor;
public string FavoritePizza;
}

这是一个通用的对话方法,但它将是你的意图方法的样子

async Task StartAsync(IDialogContext context)
{
var question = new SampleQuestion();
// Pre-populate a field. This is where you fill in with the entities you got from LUIS
question.FavoriteColor = "blue";
//Now call FormBuilder to ask the user for the remaining entities
context.Call<SampleQuestion>(new FormDialog<SampleQuestion>(question), OnSampleQuestionAnswered);
}
//this is the return from you FormBuilder. This is where you get back into you LUIS dialog and continue processing with, hopefully, all the entities you need now
public async Task OnSampleQuestionAnswered(IDialogContext context, IAwaitable<SampleQuestion> sampleQuestion)
{
var result = await sampleQuestion;
}

希望这有帮助。

我认为最简单的方法是事先使用表单从用户那里收集数据。这将具有以下优点 1(您将事先获得所有强制性数据,这使您可以对对话进行强大的控制 2( 与每次用户错过实体时请求用户添加实体时最终执行的操作相比,对 LUIS 应用的调用次数将更少。请相信我,从长远来看,节省 LUIS 的数量最终会为您节省一些钱。 因此,使用表单流事先从用户那里收集数据。我添加了以下链接来帮助您熟悉表单流的概念

https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow-advanced?view=azure-bot-service-3.0
https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-formflow?view=azure-bot-service-3.0 https://www.c-sharpcorner.com/article/formflow-in-bot-framework/

最新更新