简体   繁体   English

带有LUIS的Microsoft Bot Framework

[英]Microsoft Bot Framework with LUIS

Man am I having issue with this. 男人,我有这个问题。 I am trying to create a simple bot with the help of Luis. 我想在Luis的帮助下创建一个简单的机器人。 I have managed to create a bot and host it on azure, I have also created an intent in LUIS and an entity . 我已经设法创建了一个机器人并将其托管在azure上,我还在LUIS和实体中创建了一个intent I have created some utterances and that side is working fine. 我创造了一些话语 ,那边工作得很好。

I then created by LuisDialog in c#. 然后我用LuisDialog在c#中创建。 I had to create Cognitive Services API subscription in Azure and I copied to 2 keys it had generated into my LuisDialog . 我不得不在Azure中创建Cognitive Services API订阅,并将其生成的2个密钥复制到我的LuisDialog中

My Dialog looks like this: 我的对话框看起来像这样:

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

When I run the project and use the Bot emulator to get my responses it always hits none. 当我运行项目并使用Bot模拟器来获取我的响应时,它总是没有命中。 Even if I write a message exactly the same as the utterance . 即使我写的信息与话语完全相同。 Now I assume it is because I have confused myself. 现在我认为这是因为我迷惑了自己。 I believe there is another step after getting the keys from by Cognitive Service account to link it to LUIS endpoint, does anyone know what I am supposed to do next? 我相信在从Cognitive Service帐户获取密钥以将其链接到LUIS端点之后还有另一个步骤,是否有人知道我接下来应该做什么?


Update 更新

I was using the Alarm bot example to create my bot, but it was confusing me (mainly because I have never used Autofac before), so I have switched to the Simple Alarm bot example instead. 我使用Alarm bot示例来创建我的机器人,但它让我感到困惑(主要是因为我以前从未使用过Autofac),所以我改为使用Simple Alarm bot示例 The changes I need to make was with Global.asax: 我需要做的更改是使用Global.asax:

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

And add the LuisModel Data Annotation to the PiiiCKLuisDialog like so: 并将LuisModel数据注释添加到PiiiCKLuisDialog如下所示:

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

When I run my application, I get no errors and when I use my Microsoft Bot Emulator with the MicrosoftAppId and Secret I can type a message, but it still does the same as before. 当我运行我的应用程序时,我没有错误,当我使用我的Microsoft Bot模拟器与MicrosoftAppId和Secret我可以输入消息,但它仍然像以前一样。 It always goes to the None Luis Intent and never to the "Choose category" one. 它始终属于路易思想,永远不属于“选择类别”。 It is worth noting that the LuisResult is always null... 值得注意的是, LuisResult始终为null ...

Any ideas? 有任何想法吗?

You don't need to copy two keys. 您不需要复制两个键。

You need to only use any one of the two keys as the second argument to LuisModel. 您只需要使用两个键中的任何一个作为LuisModel的第二个参数。 For the first argument, use the app ID that looks like a GUID and can be found on LUIS.ai. 对于第一个参数,使用看起来像GUID的应用程序ID,可以在LUIS.ai上找到。

Update: 更新:

1) Here is what you use as the first parameter to [LuisModel("","")] - that's your LUIS app ID: 1)这是你用作[LuisModel("","")]的第一个参数 - 这是你的LUIS应用ID:

在此输入图像描述

2) As the second parameter, you use any of the two keys you got from Azure portal or Cognitive Services account. 2)作为第二个参数,您可以使用从Azure门户或Cognitive Services帐户获得的两个密钥中的任何一个。 Doesn't matter which of the two. 无所谓两者中的哪一个。

Finally, you can always test your endpoint and see both input params from your account at luis.ai. 最后,您可以随时测试您的终端,并在luis.ai查看您帐户中的输入参数。 Click "Publish", enter anything into "query", then press Enter. 单击“发布”,在“查询”中输入任何内容,然后按Enter键。 You will see the params in the URL. 您将在URL中看到params。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM