Luis集成抛出错误

问题描述:

我已经开始将Luis集成到我的BOT中,LUIS查询在浏览器中很好用,但它似乎在通过代码调用时从LUIS GetResult返回的内容抛出错误。Luis集成抛出错误

的LUIS查询对话框here

的源代码:

[LuisModel("2d3e39d8-632a-4e00-bf2f-d98ea4b2ed79&", "subscription Key")] 
    [Serializable] 
    public class SupportDialog : LuisDialog<object> 
    { 

     [LuisIntent("")] 
     public async Task None(IDialogContext context, LuisResult result) 
     { 
      await context.PostAsync("Sorry, I dont understand what you need"); 
      context.Wait(MessageReceived); 
     } 


     [LuisIntent("OrderStatus")] 
     public async Task OrderStatus(IDialogContext context, LuisResult result) 
     { 
      var returnMsg = "You wanted to check the order status"; 
      var orderStatus = "Dispatched"; 
      var deliveryDate = DateTime.Now.AddDays(3); 

      var entities = new List<EntityRecommendation>(result.Entities); 
      if(entities.Any((entity)=> entity.Type == "Order")) 
      { 
       var orderEntity = entities.Where((entity) => entity.Type == "Order").FirstOrDefault(); 
       var resolutionStr = orderEntity.Resolution.FirstOrDefault().Value ?? null; 
       if(!string.IsNullOrEmpty(resolutionStr)) 
       { 
        returnMsg = "Your order " + resolutionStr + " status is " + orderStatus + " and expected to deliver by " + deliveryDate.Humanize(); 
       } 
      } 

      await context.PostAsync(returnMsg); 
      context.Wait(MessageReceived); 
     } 

    } 

MessageController源代码:

internal static IDialog<object> MakeRoot() 
     { 
      return Chain.From(() => new SupportDialog()); 
     } 

     [ResponseType(typeof(void))] 
     public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity) 
     { 
      if (activity != null) 
      { 
       // one of these will have an interface and process it 
       switch (activity.GetActivityType()) 
       { 
        case ActivityTypes.Message: 
         await Conversation.SendAsync(activity, MakeRoot); 
         break; 

        case ActivityTypes.ConversationUpdate: 
        case ActivityTypes.ContactRelationUpdate: 
        case ActivityTypes.Typing: 
        case ActivityTypes.DeleteUserData: 
        default: 
         Trace.TraceError($"Unknown activity type ignored: {activity.GetActivityType()}"); 
         break; 
       } 
      } 
      return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted); 
     } 

我在BOT得到以下错误(部分摘录只)试图调试时的仿真器:

> Exception: System.Net.Http.HttpRequestException: Response status code 
> does not indicate success: 400 (Bad Request).\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Luis.LuisService.<Microsoft-Bot-Builder-Luis-ILuisService-QueryAsync>d__4.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Luis.Extensions.<QueryAsync>d__3.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.LuisDialog`1.<MessageReceived>d__7.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__4.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__7.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n 
> at 
> Microsoft.Bot.Builder.Internals.Fibers.Wait`2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()\r\n 
> at 
> Microsoft.Bot.Builder.Dialogs.Chain.FromDialog`1.<ResumeAsync>d__3.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__4.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__7.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n 
> at 
> Microsoft.Bot.Builder.Internals.Fibers.Wait`2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()\r\n 
> at 
> Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog`1.<ResumeAsync>d__3.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.<Rest>d__4.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Wait`2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Frame`1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__7.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-PollAsync>d__13.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IDialogStack-PollAsync>d__19.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__21`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.LocalizedDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.ScoringDialogTask`1.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n 
> at 
> Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__6`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.SerializingDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4`1.MoveNext()\r\n--- 
> End of stack trace from previous location where exception was thrown 
> ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task 
> task)\r\n at 
> System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at 
> Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5`1.MoveNext() 

在LuisModel删除&符号。

我想你是不小心将它从URL中复制过来的。

此外,更改您在代码中发布的订阅密钥,否则我们会盗取它。

+0

对不起,但你提到的是&符号,但我不需要在我的代码中的任何地方引用直接的LUIS模型URL ,对吧? – Vikram

+0

这是一个免费试用版,所以不会持续很长时间;) – Vikram

+0

我的意思是你的luismodel属性中的“&”标志。尝试删除它,这是一个错字。 – K48

有一行代码会抛出一个空引用异常:

var resolutionStr = orderEntity.Resolution.FirstOrDefault().Value ?? null; 

尝试下一个方式改写:

var resolutionStr = orderEntity.Resolution.FirstOrDefault()?.Value; 
+0

问题是,当我尝试调试它时,它甚至不在函数内部。我刚刚尝试评论整个部分,除了硬编码的返回消息,即使如此它也会引发相同的错误。它似乎是由Luis Intent属性本身引起的:-( – Vikram

+0

也请附上你的API控制器的代码 –

这下面的错误也可能会出现;当您发布LUIS应用下舞台插槽

Response status code does not indicate success: 400 (Bad Request) 

所以总是发布下采油槽LUIS应用

而且很明显,你必须删除符号(& )从你的LuisModel ID登录。

+1

我同意生产插槽与临时插槽的使用 - 我会追加 - 确保Luis应用程序培训和发布已完成 - 端点密钥和应用程序ID是甚至在它发生之前可用 –