2016-09-21 2 views
2

Ich habe begonnen, Luis in meinem BOT zu integrieren, die LUIS-Abfrage funktioniert gut im Browser, aber es scheint, wenn durch Code aufgerufen wird, kommt etwas von LUIS GetResult einen Fehler zurück.Luis Integration wirft Fehler

Die LUIS Abfrage ist here

Quellcode des Dialogs:

[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 Source Code:

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); 
     } 

ich folgende Fehlermeldung (Teil-Extrakt nur) in meinem BOT bekommen Emulator beim Debuggen:

> 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() 

Antwort

5

das Ampersand-Zeichen in Ihrem LuisModel entfernen.

Ich vermute, Sie haben es versehentlich von der URL kopiert.

Ändern Sie auch Ihren Abonnementschlüssel, den Sie in Ihrem Code angegeben haben, sonst werden wir ihn stehlen.

+0

Sorry, aber das kaufmännische Zeichen beziehen Sie sich auf, aber ich brauche nicht verweisen die direkte LUIS-Modell-URL irgendwo in meinem Code , richtig? – Vikram

+0

Dieses ist ein kostenloses Probeabonnement, also dauert nicht sehr lange;) – Vikram

+0

Ich meine das "&" Zeichen in Ihrem luismodel Attribut. Versuchen Sie das zu entfernen, es ist ein Tippfehler. – K48

2

Es gibt eine Zeile Code, der eine Nullreferenz Ausnahme auslösen kann:

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

versuchen, es zu umschreiben des nächsten Weges:

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

Das Problem ist, dass wenn ich versuche, es zu debuggen, es geht nicht einmal in die Funktion. Ich habe gerade versucht, den ganzen Teil zu kommentieren, außer der hartcodierten Rückmeldung und selbst dann wirft es den gleichen Fehler. Es scheint durch das Attribut Luis Intent selbst verursacht zu werden :-( – Vikram

+0

Bitte fügen Sie auch den Code von Ihrem API-Controller –

3

Dieser unter Fehler kann auch kommen; wenn Sie LUIS App unter veröffentlichen Schlitz

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

Ihre App unter Produktion Slot LUIS Also immer veröffentlichen Staging

Und natürlich müssen Sie das Ampersand entfernen (&) Melden Sie sich bei Ihrer LuisModel ID an.

+1

Ich stimme der Nutzung von Produktions-Slot vs. Staging-Slot zu - und ich würde anhängen - stelle sicher, dass Luis app train & publish abgeschlossen ist - Endpoint Key und Application Id sind verfügbar, noch bevor es passiert –