【问题标题】:Unable to map LUIS intent while using the Bot Framework v4 code使用 Bot Framework v4 代码时无法映射 LUIS 意图
【发布时间】:2020-02-11 22:47:43
【问题描述】:

我正在运行 botframework v4 代码并使用 chatbot emulator 对其进行测试。目前我无法访问 luis 意图代码存在于 [MainDialog.cs][1] 中的代码流。

下面是 MainDialog.cs 文件中的一行:

 var luisResult = await _luisRecognizer.RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);

但是,当我在 ChatBot 中输入一些消息时,每次流程都会在 [FlightBookingRecognizer.cs][2] 处结束,下面是我期望匹配/获取 luis 意图的行。

public virtual async Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, CancellationToken cancellationToken)
    => await _recognizer.RecognizeAsync(turnContext, cancellationToken);

public virtual async Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken cancellationToken)
     where T : IRecognizerConvert, new()
    => await _recognizer.RecognizeAsync<T>(turnContext, cancellationToken);

turnContext 有我们在聊天机器人中输入的消息。 我期待 _recognizer.RecognizeAsync 中的 LUIS 结果,但其中没有相关数据。 我正在尝试执行以下操作:-



But, my code flow ends here and i get error in ChatBot emulator as attached in screenshot.[![enter image description here][3]][3]


Steps to reproduce:
1. Download or pull the project from github and then Open the CoreBot.csproj  in Visual studio from this link .
[CoreBot Project][4]

2. Then select CoreBot and build it (Don't forget to add luis app id,key and host in csharp_dotnetcore\13.core-bot\appsettings.json file).
In Luis you can import this file csharp_dotnetcore\13.core-bot\CognitiveModels\FlightBooking.json and then train and publish it.
In Luis.ai go to My apps, and click Import App. Choose the file JSON file for the app you want to import and click Import.

3. Also put debug breakpoints in MainDialog.cs class (line 67 jus before switch statement) and FlightBookingRecognizer.cs class (last 2 lines ) .

4.Run the project in IIS browser mode and not in console mode ,it will open in browser you will see this link  http://localhost:3978/ 

5. In chatbot Emulator open this link http://localhost:3979/api/messages

6. You will see cards in chatbot as per attached screenshot.

7. Enter a message which is given in chatbot example i.e "Flight to paris"

8. You will see debug point ends at FlightRecognizer.cs class last line and turnContext has your message but _recognizer.RecognizeAsync doesn't carry any information about the Luis intent .

9.Also,it is not clear that LUIS intent is matched from local file or luis.ai 


More info can be found here [Microsoft documentation about this v4 code][5]
Please Help.


  [1]: https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/13.core-bot/Dialogs/MainDialog.cs
  [2]: https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/13.core-bot/FlightBookingRecognizer.cs
  [3]: https://i.stack.imgur.com/05Rbg.png
  [4]: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot
  [5]: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0&tabs=csharp

【问题讨论】:

  • 请启用调试并在遇到错误时将其中断。然后,请使用错误以及导致错误的相关代码编辑您的问题。
  • 我已经更新了调试期间代码流结束的那些行和 RecognizeAsync api 调用。
  • 如果有语法错误,你应该修复它们。就目前而言,我仍然不确定您的实际问题是什么。您需要提供有关错误、发生位置以及您期望发生的情况的更详细信息。
  • @mdrichardson-MSFT 我已经解决了该语法错误,但根据聊天机器人模拟器屏幕截图,源代码中仍然存在异常,并且如重现步骤中所述,FlightBookingRecognizer.cs 类中发生了问题。 _recognizer.RecognizeAsync 应该包含预期的意图匹配或得分,但我无法在该行中看到任何此类值。

标签: c# botframework azure-language-understanding


【解决方案1】:

V4 MessageController 应该很少(如果有的话)从骨架中改变。在这一行:

await _adapter.ProcessAsync(Request, response, _bot);

...您可以看到控制器将Request 传递给_bot。使用您的机器人来处理对话。

the CoreBot sample中,可以看到消息打到BotController后(相当于MessageController,转到DialogBot,在那里调用Dialog:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
    Logger.LogInformation("Running dialog with Message Activity.");

    // Run the Dialog with the new message Activity.
    await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
}

它“知道”这样做,因为在Startup.cs 中,它使用依赖注入来添加机器人和对话框,以便BotControllerDialogBot 可以分别使用它们:

services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();

在迁移之前,我强烈建议您设置 CoreBot 并通读它,直到您了解它的工作原理。这可能会对未来的迁移问题有所帮助。

【讨论】:

  • 非常感谢,您能否在 LUIS 意图流程中帮助我。即当我在聊天机器人中输入一些消息时,它应该将其检测为话语,然后将其映射到特定意图,并且我还在 appsettings.json 中配置了 LUIS 应用程序 ID 和密钥。
  • @AllTech CoreBot does this in MainDialog
  • 在 MainDialog.cs 中,我只找到了与 Luis intent 相关的这一行: var luisResult = await _luisRecognizer.RecognizeAsync(stepContext.Context, cancelToken);我猜在模板参数中提到了 FlightBooking,它明确地从 FlightBooking 类获取数据。
  • 另外,有一个类 FlightBookingRecognizer.cs 具有公共虚拟异步任务 RecognizeAsync(ITurnContext turnContext, CancellationToken cancelToken) => await _recognizer.RecognizeAsync(turnContext, cancelToken);当我使用调试器检查流程时(使用聊天机器人模拟器时),这就是我的代码失败的地方。
  • @AllTech 请用您的代码更新您的问题。 MainDialog 有一个switch 语句,作用于luisResult 中的每个意图
【解决方案2】:

这个问题现在已经解决了。我可以从 Luis 那里得到意图。 当我使用在 appsettings.json 中以https://xxxx.xxxx.xxxx 格式配置的 Luis 主机时 我没有得到 Luis Intent,但是在删除 https:// 之后,我现在得到了结果。 感谢大家的努力。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多