LuisDialog returns 每次 InvalidIntentHandlerException

LuisDialog returns an InvalidIntentHandlerException every time

使用 fiddler,我可以看到当查询传递到我的机器人应用程序时,LUIS 正在返回正确的 JSON 对象。它甚至包括列出的正确实体和意图。但是,我的 class 必须设置不正确,因为我在每次调用时都会收到 InvalidIntentHandlerException,这使我无法向用户发送消息。我的意图是根据我在 LUIS 中看到的内容按原样命名的,所以我不知道什么被认为是无效的。

结构如下:

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. 这与应用程序连接到的端口不同。

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

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("")],这可以帮助解决“The given key was not present in the dictionary”错误,更多信息,你可以参考这个.