r3p*_*ica 5 c# botframework azure-language-understanding
我正在尝试使用LUIS构建一个机器人,但它比我想象的要难得多.到目前为止,我已经设法创建我的LUIS应用程序并创建一个Intent和一个实体,我创建了一些似乎工作正常的话语.
然后我创建了我的机器人,并将它连接到路易斯.当我测试我的机器人时,它按预期工作.现在是有趣的部分.我想处理参数.在Luis上我向我的意图添加了一个动作:
如您所见,我添加了提示.我机器人中的代码目前看起来像这样:
/// <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.Category, out title))
return title.Entity;
// Default fallback
return null;
}
[LuisIntent("Choose category")]
public async Task ChooseCategory(IDialogContext context, LuisResult result)
{
// Get our category
var category = TryFindCategory(result);
var response = "The category you have chosen is not in the system just yet.";
switch (category)
{
case "camera":
response = $"You need help buying a { category }, is this correct?";
this.started = true;
break;
default:
if (!string.IsNullOrEmpty(category)) response = $"Sorry, PiiiCK does not deal with { category.Pluralise() } just yet.";
break;
}
// Post our response back to the user
await context.PostAsync(response);
// Execute the message recieved delegate
context.Wait(MessageReceived);
}
Run Code Online (Sandbox Code Playgroud)
我想你可以猜到我要去哪里.如果用户输入帮助我购买相机,它将进入选择类别意图并将选择正确的实体.但是如果他们输入帮助我购买,它仍将转到正确的意图,但它将没有选定的实体.我希望我的机器人能够看到并使用我在LUIS中创建的提示中的文本,当用户选择他们的实体时,我希望它使用该参数返回LUIS.
我不知道如何做到这一点,我找不到任何关于此的教程.任何帮助将不胜感激(甚至链接!)
首先,您需要确保在包含类别的话语中,将它们标记为类别实体。只需选择代表您的实体的一个或多个单词,然后在提交您的话语之前单击实际类别即可完成此操作。
这与您添加的操作参数无关。要检查操作参数,您需要浏览实际意图。IntentRecommendation有一个Actions集合属性;其中包含一个参数集合属性。
这里需要补充的是,在开发分支中,BotFramework 团队刚刚添加了对 LUIS v2 API 的支持,并添加了一些全新的功能。
例如,现在如果您的意图需要参数但未提供这些参数,LuisDialog 将执行操作。在这种情况下(看起来是您的情况),LuisDialog 将自动启动LuisActionDialog并使用您在操作参数中定义的提示消息询问用户缺少的参数。
请注意,这尚未作为 Nuget 包发布。