【问题标题】:Integrating bot framework Luis with QnA as an Intent, then re-ask user after getting to the QnA将机器人框架 Luis 与 QnA 作为 Intent 集成,然后在到达 QnA 后重新询问用户
【发布时间】:2018-08-03 03:21:19
【问题描述】:

我正在尝试制作一个充当 QnA 对话框的常见问题解答意图,它应该在进入意图后重新询问用户。

以下是我的代码,因此在集成 luis 和 QnA 时:

 [LuisIntent("FAQ")]
    public async Task FAQ(IDialogContext context, LuisResult result)
    {
        await context.PostAsync("FAQ");
        await context.Forward(new QnADialog(), ResumeAfterQnA, context.Activity, CancellationToken.None);

    }
    private async Task ResumeAfterQnA(IDialogContext context, IAwaitable<object> result)
    {
        await context.PostAsync("Back to Intent");
        context.Wait(MessageReceived);

    }

在 QnA 对话框中:

[Serializable]
[QnAMakerService("endpoint", "knowledge base id", "subscription key")]
public class QnADialog : QnAMakerDialog<object>
{
    public bool flag = false;

    public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
    {


        if (result.Answers.Length > 0 && result.Answers.FirstOrDefault().Score > 0.75 && flag)
        {
            await context.PostAsync(result.Answers.FirstOrDefault().Answer);
            await context.PostAsync("To continue using the FAQ please type another question, if not type no");
        }
        else if (originalQueryText.Contains("no"))
        {
            context.Done(true);
        }
        else
        {
            await base.DefaultMatchHandler(context, originalQueryText,result);
            flag = true;
        }
    }

}

测试结果如下: 我希望在欢迎使用常见问题解答后不显示“在 KB 中找不到好的匹配项”,但努力这样做,我已经查看了文档示例,但没有任何与我的问题类似的示例。

任何帮助将不胜感激

【问题讨论】:

    标签: c# botframework azure-language-understanding qnamaker


    【解决方案1】:

    我希望“在 KB 中找不到好的匹配项”在欢迎使用常见问题解答后不显示

    根据您的代码和要求,我修改了DefaultMatchHandler方法中的代码,适合我,您可以参考。

    public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
    {
        if (result.Answers.Length > 0 && result.Answers.FirstOrDefault().Score > 0.75 && flag)
        {
            await context.PostAsync(result.Answers.FirstOrDefault().Answer);
            await context.PostAsync("To continue using the FAQ please type another question, if not type no");
        }
        else if (originalQueryText.Contains("no"))
        {
            context.Done(true);
        }
        else
        {
            //detect if originalQueryText contains "faq"
            if (!originalQueryText.ToLower().Contains("faq"))
            {
                await base.DefaultMatchHandler(context, originalQueryText, result);
            }
            flag = true;
        }
    }
    

    测试结果:

    【讨论】:

      猜你喜欢
      • 2017-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      • 2019-11-15
      • 2020-03-02
      • 2019-02-25
      相关资源
      最近更新 更多