将 bot 框架 Luis 与 QnA 作为 Intent 集成,然后在到达 QnA 后重新询问用户
Integrating bot framework Luis with QnA as an Intent, then re-ask user after getting to the QnA
我正在尝试制作一个充当 QnA 对话框的 FAQ 意图,它应该在进入意图后重新询问用户。
下面是我的代码,所以在集成 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;
}
}
}
测试结果如下:
我希望 "No Good match found in KB" 在欢迎来到常见问题解答后不显示,但我很难这样做,我已经查看了文档样本,但没有任何类似的样本与我的问题有关。
任何帮助将不胜感激
i would like for the "No Good match found in KB" to not show after the welcome to the FAQ
根据你的代码和要求,我修改了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;
}
}
测试结果:
我正在尝试制作一个充当 QnA 对话框的 FAQ 意图,它应该在进入意图后重新询问用户。
下面是我的代码,所以在集成 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;
}
}
}
测试结果如下:
任何帮助将不胜感激
i would like for the "No Good match found in KB" to not show after the welcome to the FAQ
根据你的代码和要求,我修改了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;
}
}
测试结果: