【发布时间】: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