伙计,我有这个问题。我正在尝试在 Luis 的帮助下创建一个简单的机器人。我设法创建了一个机器人并将其托管在 azure 上,我还在LUIS 和entity中创建了一个意图。我已经创建了一些话语,并且那方面工作正常。
然后我由LuisDialog在 c# 中创建。我必须在 Azure 中创建认知服务 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 示例来创建我的 bot,但这让我感到困惑(主要是因为我以前从未使用过 Autofac),所以我改用了Simple Alarm bot 示例。我需要做的改变是使用 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时,我可以输入一条消息,但它仍然和以前一样。它总是去无路易斯意图,而不是“选择类别”之一。值得注意的是LuisResult始终为空...
有任何想法吗?