【问题标题】:How to have multiple FAQs(KBs) with same questions but different answers?如何拥有多个具有相同问题但答案不同的常见问题解答(KB)?
【发布时间】:2019-05-14 03:45:09
【问题描述】:

我无法保留聊天机器人对话的上下文(常见问题解答)。

我已根据此文档成功集成 LUIS+QnAmaker。 https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/tutorials/integrate-qnamaker-luis

我有大约 3 KB 包含相同的问题但不同的答案。聊天机器人应该能够过滤到所需的常见问题解答,并且以下答案应该来自用户选择的常见问题解答。目前,它只返回答案的第一个 KB,除非我这样表达我的问题: 我可以得到FAQ1的答案吗?或者 我可以得到FAQ2的答案吗?

希望我能从这里的社区获得一些帮助。谢谢!

【问题讨论】:

    标签: azure-language-understanding qnamaker


    【解决方案1】:

    当您对相同问题使用多个 KB 时,您可以通过向问题/答案集中添加不同的元数据来分隔答案。元数据只是名称/值对的集合。使用 QnAMakerDialog 时,您可以设置 filtering or boosting metadata,这将作为任何查询的一部分传递给 QnA Maker 服务。

    您可以创建 QnA Maker 对话框并将单个名称/值元数据对添加到对话框上的 MetadataFilter 属性。这将导致对话框仅接收标记有相同名称/值元数据的答案。

    消息控制器:

    public class MessagesController : ApiController
    {
        internal static IDialog<object> MakeRoot()
        {
            var qnaDialog = new Dialogs.MyQnADialog
            {
                MetadataFilter = new List<Metadata>()
                {
                    new Metadata()
                    {
                        Name = "knowledgeBase",
                        Value = "kb1"
    
                    }
                }
            };
    
            return qnaDialog;
        }
    
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, MakeRoot);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
    
    }
    

    同样,如果你想使用其他知识库,你可以传递其他元数据名称/值对。例如,{ Name="knowledgeBase",Value="kb2" }

    QnAMAkerDialog:

    [QnAMakerService("https://xxxx.azurewebsites.net/qnamaker/", "{EndpointKey_here}", "{KnowledgeBaseId_here}",1)]
    public class MyQnADialog : 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)
        {
            if (result.Answers.FirstOrDefault().Score > 80)
            {
                await context.PostAsync($"I found {result.Answers.Length} answer(s) that might help...{result.Answers.First().Answer}.");
            }
            else
            {
                await context.PostAsync($"Sorry, I couldn't find an answer for '{originalQueryText}'.");
            }
    
            context.Done(true);
        }
    }
    

    示例: 元数据标记

    当你测试它时,结果如下:

    • 有知识库:kb1

    • 有知识库:kb2

    希望对你有帮助!!!

    【讨论】:

    • 感谢您回答我的问题。您提供的解决方案是要在单个聊天机器人上使用吗?我想要的解决方案是使用单个聊天机器人,用户将在开始时决定要查询哪个 KB。
    • 是的,它适用于单个聊天机器人。上述解决方案是按来源过滤或分离答案的方法之一。用户通过将名称/值元数据对传递给对话框上的 MetadataFilter 属性来选择要使用的 KB。
    • 我不明白的是,为什么值元数据写在代码中?它不应该是动态的,因为它会根据用户在聊天机器人中输入的内容而变化吗?
    猜你喜欢
    • 1970-01-01
    • 2011-12-27
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 2011-02-26
    • 1970-01-01
    • 2021-09-23
    相关资源
    最近更新 更多