我有一个聊天机器人,它根据意图在QnAMaker中路由到适当的KB。例如,如果问题与项目管理相关,则它将路由到项目管理知识库。
我现在的两难境地是如何基于意图运行主动学习,并将建议路由回适当的知识库。
感谢任何人对此的建议。
我采用了微软的主动学习示例来初始化构造函数中的对话框,但无法检测到输入查询。
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
// Handle Message activity type, which is the main activity type for shown within a conversational interface
// Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
if (turnContext.Activity.Type == ActivityTypes.Message)
{
DialogContext dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);
DialogTurnResult results = await dialogContext.ContinueDialogAsync(cancellationToken);
switch (results.Status)
{
case DialogTurnStatus.Cancelled:
case DialogTurnStatus.Empty:
await dialogContext.BeginDialogAsync(_dialogHelper.ActiveLearningDialogName, _qnaMakerOptions, cancellationToken);
break;
case DialogTurnStatus.Complete:
break;
case DialogTurnStatus.Waiting:
// If there is an active dialog, we don't need to do anything here.
break;
}
await _accessors.ConversationState.SaveChangesAsync(turnContext);
}
else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
{
if (turnContext.Activity.MembersAdded != null)
{
// Send a welcome message to the user and tell them what actions they may perform to use this bot
await SendWelcomeMessageAsync(turnContext, cancellationToken);
}
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected", cancellationToken: cancellationToken);
}
}我希望根据意图和路由到正确的QnA知识库来显示主动学习结果。
发布于 2019-08-02 01:47:13
正如Matt Stannett建议的那样,你可能应该弄清楚你使用的是哪种类型的主动学习,因为QnA和LUIS都有主动学习。
您应该考虑使用Dispatch,这将路由到适当的QnA知识库、LUIS应用程序或它支持的其他杂项服务。
有关如何将LUIS intents和QnA Maker链接在一起的信息,请参阅NLP with Dispatch sample。
代码片段:
private async Task DispatchToTopIntentAsync(ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
{
switch (intent)
{
case "l_HomeAutomation":
await ProcessHomeAutomationAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
break;
case "l_Weather":
await ProcessWeatherAsync(turnContext, recognizerResult.Properties["luisResult"] as LuisResult, cancellationToken);
break;
case "q_sample-qna":
await ProcessSampleQnAAsync(turnContext, cancellationToken);
break;
default:
_logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
await turnContext.SendActivityAsync(MessageFactory.Text($"Dispatch unrecognized intent: {intent}."), cancellationToken);
break;
}
}然后,对于每个意图的逻辑,您可以处理QnA,就像您已经使用活动学习样本所做的那样。
您还可以查看CoreBot sample,帮助您了解如何将对话框与LUIS等服务捆绑在一起(这就是Dispatch --它本质上是一个父LUIS模型,路由到子服务,如QnA Maker或其他连接到它的LUIS模型)。
此外,最近从4.5版本开始,SDK现在本机支持主动学习,而不再只是处于实验阶段:
您可以查看unit tests,了解如何从您的流程qna意图直接调用Train API。
https://stackoverflow.com/questions/57308278
复制相似问题