如何在机器人项目中分析包含来自 Microsoft QnA Maker 的转义序列的问题



我正在为 Web 应用程序测试和训练一个新的 QnA 机器人,我想在遇到转义序列时打印出正确的答案格式。如何实现这种方法以使机器人识别我添加的转义序列?机器人模拟器在"\"的开头添加一个额外的"\">

我正在使用适用于 sdvk 3 和 QnA Maker 网站的机器人框架模拟器我的回答如下:

nn 1. Visit the heroes Portal website.nn 2. Select the create button.nn 3. Click “choose class” under the classes n your heroes section.nn 4. Follow the instructions provided.n If you require further assistance, please email us n at ###@$$$.comn 
using Microsoft.Bot.Builder.CognitiveServices.QnAMaker;
using System;
namespace heroes.ChatBot.Dialogs.QnA
{
    [Serializable]
    [QnAMaker("####", "###",
        "Sorry I could not find an answer to your  question", 0.5, 1, "website" )]
    public class QnAHeroesDialog : QnAMakerDialog
    {
    }
}
1.Visit the heroes Portal website.
2.Select the create button.
3.Click “choose class” under the classes n your heroes section.
4.Follow the instructions provided.n
  If you require further assistance,n
  please follow instruction.

您要查找的是 QnAMaker 提供的响应的覆盖。官方 Github 存储库中提供了一些示例:https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/CSharp/Samples/QnAMaker/QnABotWithOverrides/Dialogs/QnADialogWithOverrides.cs

简而言之,覆盖RespondFromQnAMakerResultAsync来处理此"双"问题

它将如下所示:

[Serializable]
[QnAMaker("####", "###",
    "Sorry I could not find an answer to your  question", 0.5, 1, "website" )]
public class QnAHeroesDialog : QnAMakerDialog
{
    protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults results)
    {
        if (results.Answers.Count > 0)
        {
            var foundReply = results.Answers.First().Answer;
            var response = $"{foundReply.Replace("nn", "n")}";
            await context.PostAsync(response);
        }
    }
}

我的代码可能需要快速调整Replace,因为我没有响应值的确切格式

最新更新