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

问题描述 投票:0回答:1

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

这是一个例句:

“哪个房间从下午2点到下午4点可用”

原始的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)"
  ]
}

它缺少“开始”和“结束”属性我发现这个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"]
c# botframework luis
1个回答
0
投票

要获得完整的响应,您可以将includeApiResults上的LuisRecognizer设置为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;
}

另请注意GitHub上的this issue。虽然该问题已关闭,但它被标记为版本4.4的增强功能。版本4.3是3月份的released所以4.4的工作确实已经开始了。

个人提示:当你使用datetimeV2时,你应该知道Recognizer-Text存储库,它基本上包含驱动整个事情的“引擎”。如果出现问题,请记下一长串清单,并确保在开发过程中浪费太多时间之前先检查它们。

© www.soinside.com 2019 - 2024. All rights reserved.