2016-09-21 86 views
2

我已經開始將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() 

回答

5

在LuisModel刪除&符號。

我想你是不小心將它從URL中複製過來的。

此外,更改您在代碼中發佈的訂閱密鑰,否則我們會盜取它。

+0

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

+0

這是一個免費試用版,所以不會持續很長時間;) – Vikram

+0

我的意思是你的luismodel屬性中的「&」標誌。嘗試刪除它,這是一個錯字。 – K48

2

有一行代碼會拋出一個空引用異常:

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

嘗試下一個方式改寫:

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

問題是,當我嘗試調試它時,它甚至不在函數內部。我剛剛嘗試評論整個部分,除了硬編碼的返回消息,即使如此它也會引發相同的錯誤。它似乎是由Luis Intent屬性本身引起的:-( – Vikram

+0

也請附上你的API控制器的代碼 –

3

這下面的錯誤也可能會出現;當您發佈LUIS應用下舞臺插槽

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

所以總是發佈下採油槽LUIS應用

而且很明顯,你必須刪除符號(& )從你的LuisModel ID登錄。

+1

我同意生產插槽與臨時插槽的使用 - 我會追加 - 確保Luis應用程序培訓和發佈已完成 - 端點密鑰和應用程序ID是甚至在它發生之前可用 –