我正在使用LUIS模板创建聊天机器人,并且我有一个名为StartTest的意图,其含义如下:
Begin [TestNameEntity] on [GearEntity] and [RPMEntity]
Begin [TestNameEntity] on [GearEntity]
Begin [TestNameEntity]
如果用户输入的内容与第一句话相符,则我拥有所需的所有实体。但是,如果它的输入与第二个发音匹配,我必须问他RPM。第三点,我必须询问齿轮和RPM。
但是对于第二和第三种话语,我需要知道用户对[TestNameEntity]
所说的话,像这样:
User: Begin test 1 on second gear
Bot: What RPM?
User: 2500
我该如何实现?
答案 0 :(得分:1)
一旦调用了Intent方法,就可以使用此逻辑
result.Entities[0].Type to get entity name
因此您可以迭代result.Entities
来获取用户输入的所有实体。如果缺少三个实体中的任何一个,您可以要求提示。这是如何实现的示例代码。
//global variables
public string CurrentGear { get; set; }
public string CurrentRpm { get; set; }
[LuisIntent("StartTest")]
public async Task StartTestIntent(IDialogContext context, LuisResult result)
{
if (result.Entities != null && result.Entities.Count >0)
{
//sample you will get selected entity type
//var ent1=result.Entities[0].Type;
var userValues=GetUserEntities(result);
if(userValues["GearEntity"]==null)
showGearPrompt(context);
if(userValues["RPMEntity"]==null)
showRpmPrompt(context);
}
}
private string[] GetUserEntities(LuisResult result)
{
//your logic here
//return list of entities;
}
private async Task showGearPrompt(IDialogContext context)
{
PromptDialog.Text(
context: context,
resume: OnGearOptionReceivedAsync,
prompt: "please enter Gear Value",
retry: "Sorry, I didn't understand that. Please try again."
);
}
public virtual async Task OnGearOptionReceivedAsync(IDialogContext context, IAwaitable<string> gear)
{
string response = await gear;
CurrentGear = response;
}
private async Task showRpmPrompt(IDialogContext context)
{
PromptDialog.Text(
context: context,
resume: OnRpmOptionReceivedAsync,
prompt: "please enter RPM Value",
retry: "Sorry, I didn't understand that. Please try again."
);
}
public virtual async Task OnRpmOptionReceivedAsync(IDialogContext context, IAwaitable<string> rpm)
{
string response = await rpm;
CurrentRpm = response;
}
链接到如何使用prompts