botframework如何处理luis中未被识别为意图的文本

我一直在自定义botframework(https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot)的corebot示例

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

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

botframework如何处理luis中未被识别为意图的文本

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

// 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是类型而不是变量。

jasonlevon 回答:botframework如何处理luis中未被识别为意图的文本

我很好奇,为什么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%的置信度对话。

本文链接:https://www.f2er.com/3143717.html

大家都在问