LuisDialog每次都返回一个InvalidIntentHandlerException

时间:2018-06-17 05:55:29

标签: c# visual-studio-2017 artificial-intelligence botframework luis

使用fiddler,我可以看到LUIS在将查询传递给我的bot应用程序时返回正确的JSON对象。它甚至包括列出的正确实体和意图。但是,必须在我的类中错误地设置某些内容,因为我在每次调用时都会收到InvalidIntentHandlerException,这会阻止我向用户发送消息。根据我在LUIS中看到的内容,我的意图被命名为as-is,所以我不知道什么被认为是无效的。

这是结构:

namespace BotApplication1.Dialogs
{
    [LuisModel("value...", "value...",)] //removed, but valid in the code as Fiddler shows this results in the proper endpoint
    [Serializable]
    public class MyDialog : LuisDialog<object> //also tried LuisDialog<string>
    {
        [LuisIntent("None")]
        public async Task None(IDialogContext context, LuisServiceResult result) // I also tried LuisResult instead of LuisServiceResult on a whim. No difference.
        {
            await context.PostAsync("I don't understand.");
            await Task.Delay(1000);
            await context.PostAsync("What were you saying?");
        }


        [LuisIntent("MessageDelete")]
        public async Task MessageDelete(IDialogContext context, LuisServiceResult result)
        {
            await context.PostAsync($"Message deleted!");
        }
    }
}

调试输出:

Exception thrown: 'Microsoft.Bot.Builder.Dialogs.InvalidIntentHandlerException' in mscorlib.dll
Error: None //the error returned to the MessageController by the LuisDialog class. It shows "None" even when I can see that LUIS returned a valid intent other than "None"

编辑:另外,我在输出中看到了这一点,但我不确定这是否重要:Service url localhost:6986 is not trusted and JwtToken cannot be sent to it. 这与应用程序连接的端口不同。

2 个答案:

答案 0 :(得分:1)

Microsoft.Bot.Builder/Dialogs/LuisDialog.cs中,我们可以找到:

/// <summary>
/// The handler for a LUIS intent.
/// </summary>
/// <param name="context">The dialog context.</param>
/// <param name="luisResult">The LUIS result.</param>
/// <returns>A task representing the completion of the intent processing.</returns>
public delegate Task IntentHandler(IDialogContext context, LuisResult luisResult);

因此,应将LUIS意图的处理程序定义为接受LuisResult类型参数。

此外,正如Ashwin Kumar所提到的,你可以尝试在None方法之上添加[LuisIntent("")],这可以帮助解决“ 字典中没有给定的密钥 “错误,有关详细信息,请参阅此SO thread

答案 1 :(得分:0)

当我将LuisServiceResult的每个引用替换为LuisResult时,错误消失了,我的意图方法开始发挥作用。我仍然希望能够使用LuisServiceResult,因为它包含更多信息;然而,这是一个家庭作业,所以它满足了我的迫切需要。