无法在 Azure 机器人框架中调用 Luis

Can't call Luis in Azure bot framework

我是 dotnet 以及 Luis 和 bot 框架方面的菜鸟。

我正在尝试让一些机器人样本在我的机器上运行

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

我对这个特别感兴趣

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

当我 运行 机器人时,它没有连接到 Luis(请参阅下面的错误消息)。

然后我只是 运行 正确文件夹中带有 cmd "dotnet run" 的代码。

这里是app.settingJSON。我将订阅密钥用作 LuisAPIKey,并将应用程序 ID 用作 LuisAppId。

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

机器人 运行正在我的本地主机上运行。但这就是行不通。

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\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\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.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.core-bot\Dialogs\MainDialog.cs:line 67
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) in d:\a\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\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\s\libraries\Microsoft.Bot.Builder.Dialogs\WaterfallDialog.cs:line 113
   at Microsoft.Bot.Builder.Dialogs.DialogContext.EndDialogAsync(Object result, CancellationToken cancellationToken) in d:\a\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\s\libraries\Microsoft.Bot.Builder.Dialogs\Prompts\Prompt.cs:line 147
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\s\libraries\Microsoft.Bot.Builder.Dialogs\DialogContext.cs:line 160
   at Microsoft.Bot.Builder.Dialogs.ComponentDialog.ContinueDialogAsync(DialogContext outerDc, CancellationToken cancellationToken) in d:\a\s\libraries\Microsoft.Bot.Builder.Dialogs\ComponentDialog.cs:line 84
   at Microsoft.Bot.Builder.Dialogs.DialogContext.ContinueDialogAsync(CancellationToken cancellationToken) in d:\a\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\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.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.core-bot\Bots\DialogBot.cs:line 36
   at Microsoft.Bot.Builder.BotFrameworkAdapter.TenantIdWorkaroundForTeamsMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken) in d:\a\s\libraries\Microsoft.Bot.Builder\BotFrameworkAdapter.cs:line 995
   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\s\libraries\Microsoft.Bot.Builder\MiddlewareSet.cs:line 55
   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) in d:\a\s\libraries\Microsoft.Bot.Builder\BotAdapter.cs:line 167"

如前所述,我是新手,所以对以上内容的任何见解都将不胜感激!

问题出在您的 appsettings.json 上。您只需要 LuisAPIHostName westus.api.cognitive.microsoft.com。如果这不起作用,请尝试 westus。该示例经常更改,我们计划在 LUIS 发布其新的 API 终结点后在所有示例和文档中对其进行标准化。

Here's the instructions in the Sample README

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

编辑:正如下面提到的@vikasramereddi,您还需要确保您的 LUIS 应用已发布到生产环境而不是暂存环境。