c# - 带有 LUIS 的 Microsoft Bot 框架

标签 c# azure botframework azure-language-understanding

伙计,我对此有疑问吗? 我正在尝试在路易斯的帮助下创建一个简单的机器人。 我已成功创建一个机器人并将其托管在 azure 上,我还在 LUIS 中创建了一个意图和一个实体。我已经创建了一些话语,并且该方面工作正常。

然后我通过 LuisDialog 在 c# 中创建。我必须在 Azure 中创建认知服务 API 订阅,并将其生成的 2 个 key 复制到我的 LuisDialog 中。

我的对话框如下所示:

/// <summary>
/// Entities for the PiiiCK LUIS model.
/// </summary>
public static partial class PiiiCK
{
    public const string DefaultCategory = "none";
    public const string ChooseCategoryIntent = "Choose category";
}

[Serializable]
public class PiiiCKLuisDialog : LuisDialog<object>
{

    /// <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.ChooseCategoryIntent, out title))
            return title.Entity;

        // Default fallback
        return PiiiCK.DefaultCategory;
    }

    [LuisIntent("")]
    public async Task None(IDialogContext context, LuisResult result)
    {

        // Create our response
        var response = $"Sorry I did not understand";

        // Post our response back to the user
        await context.PostAsync(response);

        // Execute the message recieved delegate
        context.Wait(MessageReceived);
    }

    [LuisIntent("Choose category")]
    public async Task ChooseCategory(IDialogContext context, LuisResult result)
    {

        // Get our category
        var category = TryFindCategory(result);
                    
        // Create our response
        var response = $"Found our entity: { category }";

        // Post our response back to the user
        await context.PostAsync(response);

        // Execute the message recieved delegate
        context.Wait(MessageReceived);
    }
}

当我运行该项目并使用机器人模拟器来获取响应时,它总是没有响应。即使我写的消息与话语完全相同。现在我想这是因为我自己感到困惑。我相信通过认知服务帐户获取 key 将其链接到LUIS端点后还有另一个步骤,有人知道我下一步应该做什么吗?

<小时/>

更新

我正在使用 Alarm bot example创建我的机器人,但这让我很困惑(主要是因为我以前从未使用过 Autofac),所以我切换到 Simple Alarm bot example反而。 我需要对 Global.asax 进行更改:

protected void Application_Start() => GlobalConfiguration.Configure(WebApiConfig.Register);

并将 LuisModel 数据注释添加到 PiiiCKLuisDialog 中,如下所示:

[Serializable]
[LuisModel("The Luis App Id", "The microsoft cognitive services subscription key")]
public class PiiiCKLuisDialog : LuisDialog<object>

当我运行我的应用程序时,我没有收到任何错误,当我使用带有 MicrosoftAppId 和 Secret 的 Microsoft Bot Emulator 时,我可以键入消息,但它仍然与以前一样。它总是转到 Luis 意图,而从不转到“选择类别”意图。 值得注意的是 LuisResult 始终为 null...

有什么想法吗?

最佳答案

您不需要复制两个 key 。

您只需使用两个键中的任意一个作为 LuisModel 的第二个参数。对于第一个参数,使用看起来像 GUID 的应用 ID,可以在 LUIS.ai 上找到。

更新:

1) 以下是您用作 [LuisModel("","")] 第一个参数的内容 - 这是您的 LUIS 应用 ID:

enter image description here

2) 作为第二个参数,您可以使用从 Azure 门户或认知服务帐户获取的两个 key 中的任意一个。两者中的哪一个并不重要。

最后,您始终可以测试您的端点并查看来自 luis.ai 帐户的两个输入参数。单击“发布”,在“查询”中输入任何内容,然后按 Enter。您将在 URL 中看到参数。

enter image description here

关于c# - 带有 LUIS 的 Microsoft Bot 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576431/

相关文章:

python - 如何使用 python 和 bot 框架创建一个简单的 Skype 机器人

c# - MS BotFramework 数据保存,BotState

c# - 请求无法完成(未找到)

azure - 过滤子句无效。微软Graph

azure - 为什么应用程序洞察将 400 错误请求记录为成功请求而不记录异常

azure - 使用 Azure Powershell 在应用服务环境中创建 Azure 应用服务计划

c# - 为什么我的无效 WCF 消息没有被记录?

c# - 如何在输入参数中传递加号?

c# - 测试 Windows 服务项目花费的时间太长

c# - Bot Framework Composer - 读取应用程序设置