简体   繁体   中英

Can't call Luis in Azure bot framework

在此处输入图像描述 I am a noob in dotnet as well as on Luis and bot framework.

I am trying to make some bot samples work on my machine from

https://github.com/microsoft/BotBuilder-Samples .

I am interested in this one particularly in

https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot

When i run the bot, it does not connect to Luis (see error message below).

  • I created and published an app in Luis by importing the intent supplied in the app.
  • I wrote LuisAppId,LuisAPIKey and LuisAPIHostName in the correct JSON file (see below).
  • I added the dotnet library to the project: dotnet add package Cognitive.LUIS.Programmatic

I then just run the code with the cmd "dotnet run" in the correct folder.

Here the app.setting JSON. I used subscription-key as LuisAPIKey, and app ID as LuisAppId.

{
  "MicrosoftAppId": "",
  "MicrosoftAppPassword": "",
  "LuisAppId": "2aa2b9c5-#######################7b557",
  "LuisAPIKey": "1069d###############4347da9",
  "LuisAPIHostName": "westus.api.cognitive.microsoft.com/luis/api/v2.0"
}

The bot is running on my localhost. But it just does not work.

bot: What can I help you with today? Say something like “Book a flight from Paris to Berlin on March 22, 2020”

me: “Please Book a flight from Paris to Berlin on March 22, 2020”

bot:"The bot encounted an error or bug."

bot:"To continue to run this bot, please fix the bot source code"


On the cmd line : 
"fail: Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter[0]
      [OnTurnError] unhandled error : Operation returned an invalid status code 'NotFound'
Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.Models.APIErrorException: Operation returned an invalid status code 'NotFound'
   at Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.Prediction.ResolveWithHttpMessagesAsync(String appId, String query, Nullable`1 timezoneOffset, Nullable`1 verbose, Nullable`1 staging, Nullable`1 spellCheck, String bingSpellCheckSubscriptionKey, Nullable`1 log, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.PredictionExtensions.ResolveAsync(IPrediction operations, String appId, String query, Nullable`1 timezoneOffset, Nullable`1 verbose, Nullable`1 staging, Nullable`1 spellCheck, String bingSpellCheckSubscriptionKey, Nullable`1 log, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.RecognizeInternalAsync(ITurnContext turnContext, LuisPredictionOptions predictionOptions, Dictionary`2 telemetryProperties, Dictionary`2 telemetryMetrics, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.AI.LUIS\LuisRecognizer.cs:line 345
   at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.RecognizeAsync[T](ITurnContext turnContext, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.AI.LUIS\LuisRecognizer.cs:line 163
   at Microsoft.BotBuilderSamples.FlightBookingRecognizer.RecognizeAsync[T](ITurnContext turnContext, CancellationToken cancellationToken) in C:\Users\flabare\botbuilder-samples\samples\csharp_dotnetcore\13.core-bot\FlightBookingRecognizer.cs:line 38
   at Microsoft.BotBuilderSamples.Dialogs.MainDialog.ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) in C:\Users\flabare\botbuilder-samples\samples\csharp_dotnetcore\13.core-bot\Dialogs\MainDialog.cs:line 67
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\WaterfallDialog.cs:line 166
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.RunStepAsync(DialogContext dc, Int32 index, DialogReason reason, Object result, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\WaterfallDialog.cs:line 188
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.ResumeDialogAsync(DialogContext dc, DialogReason reason, Object result, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\WaterfallDialog.cs:line 113
   at Microsoft.Bot.Builder.Dialogs.DialogContext.EndDialogAsync(Object result, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 196
   at Microsoft.Bot.Builder.Dialogs.Prompt`1.ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\Prompts\Prompt.cs:line 147
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 160
   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\ComponentDialog.cs:line 84
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 160
   at Microsoft.Bot.Builder.Dialogs.DialogExtensions.RunAsync(Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor`1 accessor, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogExtensions.cs:line 18
   at Microsoft.BotBuilderSamples.Bots.DialogBot`1.OnMessageActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken) in C:\Users\flabare\botbuilder-samples\samples\csharp_dotnetcore\13.core-bot\Bots\DialogBot.cs:line 48
   at Microsoft.BotBuilderSamples.Bots.DialogBot`1.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\Users\flabare\botbuilder-samples\samples\csharp_dotnetcore\13.core-bot\Bots\DialogBot.cs:line 36
   at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotFrameworkAdapter.cs:line 995
   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\MiddlewareSet.cs:line 55
   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\1\s\libraries\Microsoft.Bot.Builder\BotAdapter.cs:line 167"

As mentioned I am new to this, so any insights on the above would be greatly appreciated!

The problem is in your appsettings.json . You need your LuisAPIHostName to be only westus.api.cognitive.microsoft.com . If that doesn't work, try just westus . The sample has changed frequently and we plan on standardizing it across all of the samples and documentation once LUIS releases their new API endpoints.

Here's the instructions in the Sample README

Here's a Pull Request noting how common this issue is

Edit: As @vikasramereddi mentioned below, you also need to make sure your LUIS app is published to Production and not Staging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM