如何在我的机器人项目中解析包含来自 Microsoft QnA Maker 的转义序列的问题?
How do I parse a question that contains escape sequences from Microsoft QnA Maker in my bot project?
我正在为我的 Web 应用程序测试和训练一个新的 QnA 机器人,我想在它遇到转义序列时打印出正确的答案格式。我如何实施这种方法才能让机器人识别我添加的转义序列?机器人模拟器在'\n\n'
的开头添加了一个额外的'\'
我正在为 sdvk 3 和 QnA Maker 网站使用 Bot Framework 模拟器
我的回答如下:
\n\n 1. Visit the heroes Portal website.\n\n 2. Select the create button.\n\n 3. Click “choose class” under the classes \n your heroes section.\n\n 4. Follow the instructions provided.\n If you require further assistance, please email us \n at ###@$$$.com\n
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
来处理这个 "double \n" 问题
它将如下所示:
[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("\n\n", "\n")}";
await context.PostAsync(response);
}
}
}
我的代码可能需要针对 Replace
进行快速调整,因为我没有您的响应值的确切格式
我正在为我的 Web 应用程序测试和训练一个新的 QnA 机器人,我想在它遇到转义序列时打印出正确的答案格式。我如何实施这种方法才能让机器人识别我添加的转义序列?机器人模拟器在'\n\n'
的开头添加了一个额外的'\'我正在为 sdvk 3 和 QnA Maker 网站使用 Bot Framework 模拟器 我的回答如下:
\n\n 1. Visit the heroes Portal website.\n\n 2. Select the create button.\n\n 3. Click “choose class” under the classes \n your heroes section.\n\n 4. Follow the instructions provided.\n If you require further assistance, please email us \n at ###@$$$.com\n
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
来处理这个 "double \n" 问题
它将如下所示:
[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("\n\n", "\n")}";
await context.PostAsync(response);
}
}
}
我的代码可能需要针对 Replace
进行快速调整,因为我没有您的响应值的确切格式