我正在尝试使用LUIS构建一个机器人,但是它比我想象的要难得多。
到目前为止,我已经成功创建了LUIS应用程序,并创建了一个 Intent 和一个实体,并创建了一些话机,这些看起来不错。

然后,我创建了我的机器人,并将其连接到Luis。当我测试我的机器人时,它按预期运行。
现在是有趣的部分。我想处理参数。在Luis上,我向意图添加了一个操作:

c# - Microsoft Bot Framework,LUIS和Action参数-LMLPHP

如您所见,我已经添加了一个提示。
我的漫游器中的代码当前如下所示:

/// <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);
}

我想你可以猜得出我要去哪里。如果用户键入帮助我购买相机,它将进入选择类别目的,并将选择正确的实体
但是,如果他们键入,请帮助我购买,它仍然会转到正确的Intent,但不会选择实体。我希望我的机器人看到它并使用在LUIS中创建的提示中的文本,当用户选择其实体时,我希望它使用该参数返回LUIS。

我不知道该怎么做,也找不到任何教程。
任何帮助,将不胜感激(甚至链接!)

最佳答案

首先,您需要确保在包含类别的话语中将其标记为“类别”实体。只需选择代表您实体的一个或多个单词,然后单击实际类别,然后再提交话语即可完成此操作。

c# - Microsoft Bot Framework,LUIS和Action参数-LMLPHP

这与您添加的操作参数无关。要检查 Action 参数,您需要浏览实际意图。 IntentRecommendation具有Actions集合属性;其中包含Parameters集合属性。

c# - Microsoft Bot Framework,LUIS和Action参数-LMLPHP

在这里添加的是,在develop分支中,BotFramework团队刚刚添加了对LUIS v2 API的支持,并添加了一些全新的功能。

例如,如果您的意图需要参数而未提供参数,则现在LuisDialog将起作用。在那种情况下(看来是您的情况),LuisDialog将使用您在action参数中定义的Prompt消息将automatically launch变成LuisActionDialog,并要求用户提供缺少的参数。

请注意,这尚未发布为Nuget包。

10-06 15:25
查看更多