C# 路易斯在两种意图之间做出选择

C# 路易斯在两种意图之间做出选择,c#,botframework,microsoft-cognitive,azure-language-understanding,C#,Botframework,Microsoft Cognitive,Azure Language Understanding,如果luis对一次对话的最高意图得分为0.15,第二个为0.14,机器人是否可以询问用户他们是指第一个意图还是第二个意图?如果是,怎么做?我一直在文档样本中搜索,似乎没有任何解决方案,只是说了越来越多的话,这样就不会发生这种情况;对吗 如果luis对一次对话的最高意图得分为0.15,第二个为0.14,机器人是否可以询问用户他们是指第一个意图还是第二个意图?如果是,怎么做 是的,我们可以达到这个要求。下面的示例代码适用于我,您可以参考它 [Serializable] public class My

如果luis对一次对话的最高意图得分为0.15,第二个为0.14,机器人是否可以询问用户他们是指第一个意图还是第二个意图?如果是,怎么做?我一直在文档样本中搜索,似乎没有任何解决方案,只是说了越来越多的话,这样就不会发生这种情况;对吗

如果luis对一次对话的最高意图得分为0.15,第二个为0.14,机器人是否可以询问用户他们是指第一个意图还是第二个意图?如果是,怎么做

是的,我们可以达到这个要求。下面的示例代码适用于我,您可以参考它

[Serializable]
public class MyLuisDialog : LuisDialog<object>
{
    public MyLuisDialog() : base(new LuisService(new LuisModelAttribute("xxxxxxx", 
        "xxxxxxx", 
        domain: "westus.api.cognitive.microsoft.com")))
    {
    }


    //modify Luis request to make it return all intents instead of just the topscoring intent
    protected override LuisRequest ModifyLuisRequest(LuisRequest request)
    {
        request.Verbose = true;
        return request;
    }

    protected override async Task DispatchToIntentHandler(IDialogContext context, IAwaitable<IMessageActivity> item, IntentRecommendation bestIntent, LuisResult result)
    {

        if (bestIntent.Intent == "FindFood" || bestIntent.Intent == "BuyFood")
        {
            if (result.Intents[0].Score - result.Intents[1].Score < 0.1)
            {
                bestIntent.Intent = "FindOrBuyFood";
                bestIntent.Score = 1;
            }
        }

        await base.DispatchToIntentHandler(context, item, bestIntent, result);
    }

    [LuisIntent("Greeting")]
    public async Task GreetingIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    //...
    //other intent handlers
    //...

    [LuisIntent("FindFood")]
    [LuisIntent("BuyFood")]
    public async Task FoodIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    [LuisIntent("FindOrBuyFood")]
    public async Task FindOrBuyFoodIntent(IDialogContext context, LuisResult result)
    {
        var food = "food";

        if (result.Entities.Count() > 0)
        {
            food = result.Entities[0].Entity;
        }

        List<string> options = new List<string>() { $"Find {food}", $"Buy {food}" };

        PromptDialog.Choice(
            context: context,
            resume: ChoiceReceivedAsync,
            options: options,
            prompt: "Hi. Please Select one option :",
            retry: "Please try again.",
            promptStyle: PromptStyle.Auto
            );
    }

    private async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var option = await result;

        //your code logic here

        await context.PostAsync($"You selected the '{option}'");

        context.Wait(MessageReceived);
    }

    private async Task ShowLuisResult(IDialogContext context, LuisResult result)
    {
        await context.PostAsync($"You have reached {result.Intents[0].Intent} intent.");
        context.Wait(MessageReceived);
    }
} 
[可序列化]
公共类对话框:LuisDialog
{
public MyLuisDialog():base(新LuisService(新LuisModelAttribute(“xxxxxxx”),
“xxxxxxx”,
域名:“westus.api.cognitive.microsoft.com”))
{
}
//修改Luis请求,使其返回所有意图,而不仅仅是上取芯意图
受保护的覆盖LuisRequest修改LuisRequest(LuisRequest请求)
{
request.Verbose=true;
返回请求;
}
受保护的重写异步任务DispatchToIntentHandler(IDialogContext上下文、IAwaitable项、IntentRecommension bestIntent、LuisResult结果)
{
if(bestIntent.Intent==“FindFood”| | bestIntent.Intent==“BuyFood”)
{
if(result.Intents[0]。分数-result.Intents[1]。分数<0.1)
{
bestIntent.Intent=“findorbyfood”;
最佳意图得分=1;
}
}
wait base.DispatchToIntentHandler(上下文、项目、最佳意图、结果);
}
[问候语]
公共异步任务GreetingIntent(IDialogContext上下文,LuisResult结果)
{
等待这个。ShowLuisResult(上下文、结果);
}
//...
//其他意图处理程序
//...
[路易辛顿(“FindFood”)]
[路易辛顿(“购买食品”)]
公共异步任务FoodIntent(IDialogContext上下文,LuisResult结果)
{
等待这个。ShowLuisResult(上下文、结果);
}
[路易辛顿(“FindOrBuyFood”)]
公共异步任务FindOrBuyFoodIntent(IDialogContext上下文,LuisResult结果)
{
var food=“food”;
if(result.Entities.Count()>0)
{
食物=结果。实体[0]。实体;
}
列表选项=新列表(){$“查找{food}”,$“购买{food}”;
提示对话框。选择(
上下文:上下文,
简历:ChoiceReceivedAsync,
选项:选项,
提示:“您好,请选择一个选项:”,
重试:“请重试。”,
promptStyle:promptStyle.Auto
);
}
专用异步任务ChoiceReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
var选项=等待结果;
//你的代码逻辑在这里
wait context.PostAsync($“您选择了“{option}”);
Wait(MessageReceived);
}
专用异步任务ShowLuisResult(IDialogContext上下文,LuisResult结果)
{
wait context.PostAsync($“您已到达{result.Intents[0].Intent}Intent.”);
Wait(MessageReceived);
}
} 
测试结果:


luis对话的最高意图分数是0.15,第二个是0.14
你能分享你在luis应用程序中定义和创建的意图和实体的详细信息吗?我的luis应用程序中有太多的意图,但我想这是因为我的意图中有3个与支付相关(财产、税收、图书馆服务)其中结果分别为0.11和0.09。虽然这三个字都没有,只是一句话。尽管有可能让机器人重新询问用户吗?嗨@user3646742,我创建了一个示例来满足您的要求,请参考我的回复。