0

我一直致力于定制 botframework 的 corebot 示例(https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot

在尝试使其工作后,我意识到提供的示例没有处理与 Luis 意图无关的用户答案。

例如,我希望机器人在用户说“blabla”时提示用户重复。

在此处输入图像描述

在主对话框的代码下方。当我说“blabla”(路易斯显然无法识别)时,机器人会停止并从头开始重新启动。

// Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
            var luisResult = await _luisRecognizer.RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);
            switch (luisResult.TopIntent().intent)
            {
                case FlightBooking.Intent.BookFlight:
                    await ShowWarningForUnsupportedCities(stepContext.Context, luisResult, cancellationToken);

                    // Initialize BookingDetails with any entities we may have found in the response.
                    var bookingDetails = new BookingDetails()
                    {
                        // Get destination and origin from the composite entities arrays.
                        Destination = luisResult.ToEntities.Airport,
                        Origin = luisResult.FromEntities.Airport,
                        TravelDate = luisResult.TravelDate,
                    };

                    // Run the BookingDialog giving it whatever details we have from the LUIS call, it will fill out the remainder.
                    return await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken);

                case FlightBooking.Intent.GetWeather:
                    // We haven't implemented the GetWeatherDialog so we just display a TODO message.
                    var getWeatherMessageText = "TODO: get weather flow here";
                    var getWeatherMessage = MessageFactory.Text(getWeatherMessageText, getWeatherMessageText, InputHints.IgnoringInput);
                    await stepContext.Context.SendActivityAsync(getWeatherMessage, cancellationToken);
                    break;

                default:
                    // Catch all for unhandled intents
                    var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})";
                    var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                    await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);
                    break;
            }

            return await stepContext.NextAsync(null, cancellationToken);
        }

我有办法处理这些吗?它可能真的很有用,我可以带着任何其他意图离开循环。


编辑


根据@billoverton 的回答,如果在切换之前,我会尝试添加此内容。

if (luisResult.TopIntent().score < 0.5) 
{ FlightBooking.Intent = FlightBooking.Intent.None; } 

但它说 FlightBooking.Intent 是一种类型而不是变量。

4

1 回答 1

1

我很好奇为什么 LUIS 没有为你返回 None 。我认为这是标准行为。但无论如何,这可能是因为您试图直接打开 LUIS 结果。我将意图保存到一个变量并打开它。我正在使用 nodejs,但您应该能够在 C# 中遵循和实现类似的东西。所以这是我对 LUIS 和意图切换的调用。

const results = await this.luisRecognizer.recognize(context);
var topIntent = LuisRecognizer.topIntent(results);
if (results.intents[topIntent].score < 0.5) {
    topIntent = 'None';
}

if (!dc.context.responded) {
    switch (dialogResult.status) {
        case DialogTurnStatus.empty:
            switch (topIntent) {
                case Intent1:
                    break;
                case Intent2:
                    break;
                deafult:
                    break;
            }
        case DialogTurnStatus.waiting:
            break;
        case DialogTurnStatus.complete:
            break;
        default:
            await dc.cancelAllDialogs();
            break;
    }
}

如果置信度低,我在这里要做的另一件事是手动将意图设置为无。我宁愿让机器人不理解,也不愿以 20% 的信心开始对话。

于 2019-11-07T16:21:49.207 回答