如何使用不同的QnA数据集(JSON)通信单个ChatBot ..
Ex: QnA1(JSON文件) QnA2(JSON文件)
和Single Bot应用程序。
当我启动with site1时,Bot将与QnA1数据通信。 当我启动with site2时,Bot将与QnA2数据进行通信。
这里我只有一个Bot。
请告诉我如何将KNOWLEDGE_BASE_ID传递给Bot。
答案 0 :(得分:1)
当我启动with site1时,Bot将与QnA1数据通信。当我启动with site2时,Bot将与QnA2数据进行通信。
BotFramework的用户界面基于@RequestMapping("/get_product_by_location")
public List<ProductStock> getProductByLocation(HttpServletRequest request, @RequestParam String code){
HttpSession session = request.getSession();
Location location = session != null ? (Location) session.getAttribute("location") : null;
System.out.println(code+" "+location);
List<ProductStock> products = productService.getProductByLocation(code,location);
System.out.println(products);
return products;
}
,因此我只能猜测您的Dialog
和site 1
表示两个对话框,每个对话框都是基于QnA构建的。
请告诉我如何将KNOWLEDGE_BASE_ID传递给Bot。
然后将KNOWLEDGE_BASE_ID传递给您的机器人,您可以使用site 2
进行对话。例如在.Net SDK中:
QnAMakerAttribute
如果你正在使用node.js SDK进行开发,你可以像这样传递id:
[QnAMakerAttribute("Your-subscription-key", "Your-Qna-KnowledgeBase-ID", "No Answer in Knowledgebase.", 0.5)]
[Serializable]
public class QnADialog1 : QnAMakerDialog
{
}
有关详情,请参阅Blog samples,其中包括C#和node.js版本的演示。
如果您仍想询问如何在一个机器人中使用两个知识库,请发表评论并告诉我您使用哪个sdk进行开发,.net或node.js?我会回来更新我的答案。
<强>更新强>
您可以像这样编码:
var recognizer = new builder_cognitiveservices.QnAMakerRecognizer({
knowledgeBaseId: 'Your-Qna-KnowledgeBase-ID', // process.env.QnAKnowledgebaseId,
subscriptionKey: 'Your-Qna-KnowledgeBase-Password'}); //process.env.QnASubscriptionKey});
在[Serializable]
public class RootDialog : IDialog<object>
{
private string currentKB;
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
if (activity.Text == "reset") //handle reset
currentKB = null;
else if (activity.Text == "qna1" || currentKB == "qna1")
{
currentKB = "qna1";
if (activity.Text == "qna1")
await context.PostAsync("this is qna 1");
else
await context.Forward(new Dialogs.QnADialog1(), this.QnAReceivedAsync, activity, CancellationToken.None);
}
else if (activity.Text == "qna2" || currentKB == "qna2")
{
currentKB = "qna2";
if (activity.Text == "qna2")
await context.PostAsync("this is qna 2");
else
await context.Forward(new Dialogs.QnADialog2(), this.QnAReceivedAsync, activity, CancellationToken.None);
}
else
{
var reply = activity.CreateReply("Please choose a knowledge base...");
var heroCard = new HeroCard
{
Title = "Knowledge bases",
Text = "Which one do you want to choose?",
Buttons = new List<CardAction>
{
new CardAction(ActionTypes.ImBack, "QnA base 1", value:"qna1"),
new CardAction(ActionTypes.ImBack, "QnA base 2", value:"qna2")
}
};
Attachment attachment = heroCard.ToAttachment();
reply.Attachments.Add(attachment);
await context.PostAsync(reply);
context.Wait(MessageReceivedAsync);
}
}
public async Task QnAReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
context.Wait(MessageReceivedAsync);
}
}
中将MessagesController
作为对话框堆栈的根目录:
RootDialog
最后由if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
和QnADialog1
,我只传递了知识库ID和密钥。