【问题标题】:Microsoft Bot Framework with LUIS带有 LUIS 的 Microsoft Bot 框架
【发布时间】:2016-11-13 16:57:43
【问题描述】:

伙计,我有这个问题吗? 我正在尝试在 Luis 的帮助下创建一个简单的机器人。 我设法创建了一个机器人并将其托管在 azure 上,我还在 LUIS 中创建了一个 intent 和一个 entity。我已经创建了一些话语,并且这方面工作正常。

然后我由 LuisDialog 在 c# 中创建。我必须在 Azure 中创建 Cognitive Services API 订阅,并将它复制到我的 LuisDialog 中生成的 2 个密钥。

我的对话框如下所示:

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

当我运行该项目并使用 Bot 模拟器 来获得我的响应时,它总是没有命中。即使我写的消息与话语完全相同。现在我认为这是因为我自己搞糊涂了。我相信在从 认知服务 帐户获取密钥以将其链接到 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 时,我可以输入一条消息,但它仍然和以前一样。它总是指向 None Luis Intent,而不是“选择类别”。 值得注意的是,LuisResult 始终为 null...

有什么想法吗?

【问题讨论】:

  • 您在设置密钥吗? (即 [LuisModel("YourModelId", "YourSubscriptionKey")])
  • 您确定您已在 Luis.ai 上发布了您的 luis 意图和实体吗?它们需要发布才能工作

标签: c# azure botframework azure-language-understanding


【解决方案1】:

您不需要复制两个密钥。

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

更新:

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

2) 作为第二个参数,您可以使用从 Azure 门户或认知服务帐户获得的两个密钥中的任何一个。两者中的哪一个无关紧要。

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

【讨论】:

  • 我将其更改为使用第一个密钥作为 luis 应用程序 ID,第二个使用认知服务帐户密钥,但它的作用完全相同。它总是不返回任何内容。
  • 只是为了解释一下,我的 web.config 文件中有 MicrosoftAppId 和 Secret。我现在已将 LuisModel 数据属性(使用 luis 应用程序 ID 和订阅密钥)添加到 PiiiCKLuisDialog 并停止使用 Autofac 以查看这是否是一个问题,我已经更改了 Post 方法添加到我的编辑中。
  • luis 发布 url 中的订阅密钥,这是从哪里来的?
  • r3plica 你训练好你的模型并发布应用了吗?
  • 想通了,在 luis 中有一个地方可以添加您的认知服务密钥。
猜你喜欢
  • 1970-01-01
  • 2020-02-29
  • 2017-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多