LuisService 不序列化 botframework V4 中 DateTimeV2 实体的所有分辨率值

LuisService does not serialize all resolution values for DateTimeV2 entity in botframework V4

我正在开发一个可以用来预订房间的机器人。我正在使用 luis 内置日期时间实体来检测会议的开始和结束时间。 Luis 可以很好地识别日期时间,但我无法在机器人代码的 luisResult 中找到它们。我正在使用 Microsoft.Bot.Builder V4.3.2

这是例句:

"which room is available from 2pm to 4pm"

原始 luisResult 包含

"entities": [
{
  "entity": "from 2pm to 4pm",
  "type": "builtin.datetimeV2.timerange",
  "startIndex": 24,
  "endIndex": 38,
  "resolution": {
    "values": [
      {
        "timex": "(T14,T16,PT2H)",
        "type": "timerange",
        "start": "14:00:00",
        "end": "16:00:00"
      }
    ]
  }
}

]

这是我在代码中使用 LuisService 得到的结果:

{
  "type": "timerange",
  "timex": [
     "(T14,T16,PT2H)"
  ]
}

缺少 "start" 和 "end" 属性 我发现这个bug在botframework V3也有,但是在V3.8已经解决了 https://github.com/Microsoft/BotBuilder/issues/2764

这是对 luisService 的调用:

var luisResults = await _services.LuisServices[LuisConfiguration].RecognizeAsync(dc.Context, cancellationToken);

我预计 "start" 和 "end" 会针对 DateTime v2 实体进行序列化。

编辑: 解决此问题的一种方法是在 bot 服务的实例化中启用完整的 api 响应:

var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint());
var recognizer = new LuisRecognizer(app, includeApiResults: true);

现在可以在

中获得完整的结果
luisResults.Properties["luisResult"]

要获得完整响应,您可以将 LuisRecognizer 上的 includeApiResults 设置为 true

var recognizer = new LuisRecognizer(application, includeApiResults: true);

Here 是开关在引擎盖下的实际工作方式以及它存储结果的位置。

如果您想自己改进处理,Luis with AppInsights.

中的机器人生成器示例中提供了构建改进版 LuisRecognizer 的良好起点
/// <summary>
/// Initializes a new instance of the <see cref="TelemetryLuisRecognizer"/> class.
/// </summary>
/// <param name="application">The LUIS application to use to recognize text.</param>
/// <param name="predictionOptions">The LUIS prediction options to use.</param>
/// <param name="includeApiResults">TRUE to include raw LUIS API response.</param>
/// <param name="logOriginalMessage">TRUE to include original user message.</param>
/// <param name="logUserName">TRUE to include user name.</param>
public TelemetryLuisRecognizer(LuisApplication application, LuisPredictionOptions predictionOptions = null, bool includeApiResults = false, bool logOriginalMessage = false, bool logUserName = false)
    : base(application, predictionOptions, includeApiResults)
{
    LogOriginalMessage = logOriginalMessage;
    LogUsername = logUserName;
}

另请注意 this issue on GitHub. While the issue is closed, it is tagged as enhancement for Version 4.4. Version 4.3 was released 三月,因此 4.4 的工作确实已经开始。

个人提示: 当您使用 datetimeV2 时,您应该了解 Recognizer-Text 存储库,它基本上包含驱动 "engine"整件事。如果出现问题,请记下一长串问题,并确保始终先检查它们,以免在开发中浪费太多时间。