如果意图为无,则使用Luis对话框,我想转发到QnAMakerDialog以匹配QnAPair。
如果找到了对,则返回答案并返回到luis堆栈。如果一对没有发送消息“抱歉我不知道”并返回luis堆栈等待另一条消息。
我成功收到await context.Forward(qnaDialog, AfterQnADialog, messageToForward, CancellationToken.None)
的回复。返回响应后,模拟器抛出Exception Stack is empty [File Type 'text/plain']
我认为错误发生在 AfterQnADialog 中,但不确定如何修复它。在此先感谢您的帮助。
消息控制器*
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootLuisDialog());
}
Luis Dialog Class
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, IAwaitable<IMessageActivity> message ,LuisResult result)
{
var qnaDialog = new QnADialog();
var messageToForward = await message;
await context.Forward(qnaDialog, AfterQnADialog, messageToForward, CancellationToken.None);
}
...
private async Task AfterQnADialog(IDialogContext context, IAwaitable<object> result)
{
var messageHandled = await result;
if (messageHandled == null)
{
await context.PostAsync("I’m not sure what you want.");
}
context.Wait(this.MessageReceived);
}
QnAMakerDialog类
[QnAMaker("<QnAMakerAppID", "QnAMakerApiKey", "I don't understand this right now! Try another query!", 0.10, 1)]
public class QnADialog : QnAMakerDialog
{
}
}
答案 0 :(得分:1)
我使用以下示例代码进行测试,以便在没有意图匹配的情况下从LUIS对话框将消息转发到QnAMakerDialog,这对我有用,您可以参考它。
在LUIS对话框中:
[LuisIntent("None")]
public async Task NoneIntent(IDialogContext context, LuisResult result)
{
await context.Forward(new QnADialog(), AfterQnADialog, context.Activity, CancellationToken.None);
}
<强> QnAMakerDialog:强>
using Microsoft.Bot.Builder.Dialogs;
using QnAMakerDialog;
using QnAMakerDialog.Models;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace HalChatBot.Dialogs
{
[Serializable]
[QnAMakerService("{subscriptionKey_here}", "{ knowledgeBaseId_here}")]
public class QnADialog : QnAMakerDialog<object>
{
public override async Task NoMatchHandler(IDialogContext context, string originalQueryText)
{
await context.PostAsync($"Sorry, I couldn't find an answer for '{originalQueryText}'.");
context.Done(false);
}
public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
{
await context.PostAsync($"I found {result.Answers.Length} answer(s) that might help...{result.Answers.First().Answer}.");
context.Done(true);
}
}
注意:我收到同样的异常消息:&#34;堆栈为空&#34;如果我不覆盖 NoMatchHandler 并调用context.Done
将控制权传递回父对话框。
<强>更新强>
您的项目似乎正在使用Microsoft.Bot.Builder.CognitiveServices.QnAMaker。如果是这种情况,则无需安装QnAMakerDialog。为了避免&#34; Stack是空的&#34;错误,您可以覆盖RespondFromQnAMakerResultAsync
并调用context.Done
将控制权传递回父对话框。
[Serializable]
[QnAMaker("{subscriptionKey_here}", "{knowledgeBaseId_here}")]
public class BaiscQnaDialog : Microsoft.Bot.Builder.CognitiveServices.QnAMaker.QnAMakerDialog
{
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
await context.PostAsync($"I found {result.Answers.Count} answer(s) that might help...{result.Answers.First().Answer}.");
context.Done(true);
}
}
测试结果: