【问题标题】:How to pass metadata to QnAMaker Request如何将元数据传递给 QnAMaker 请求
【发布时间】:2018-09-06 06:35:47
【问题描述】:

我正在尝试将元数据过滤器传递给我的 QnAMakerDialog 请求,但无法弄清楚如何去做。我已尝试将值添加到转发的对话框中,但这不起作用。

LuisDialog.cs 方法调用 QnAMaker

public List<Metadata> _metadataFilter { get; set; }

[LuisIntent("")]
[LuisIntent("None")]
public async Task NoneIntent(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
{
    string filterValue = context.UserData.GetValue<string>("filter");
    var messageToForward = await message;
    var qnaDialog = new QnADialog();
    _metadataFilter = new List<Metadata>()
    {
        new Metadata()
        {
            Name = "filter",
            Value = filterValue
        }
    };

    await context.Forward(qnaDialog, AfterQnADialog, messageToForward, CancellationToken.None);
}

QnAMakerDialog.cs

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using QnAMakerDialog;
using QnAMakerDialog.Models;

namespace ChatBot.Dialogs
{

    [Serializable]
    [QnAMakerService("","","")]
    public class QnADialog : QnAMakerDialog <bool>
    {

        public override async Task NoMatchHandler(IDialogContext context, string originalQueryText)
        {
            await context.PostAsync($"Sorry, I don't know '{originalQueryText}' yet");
            context.Done(this);
        }

        public override async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
        {
            // Posting top QnA Maker result to user
            var messageActivity = (result.Answers.First().Answer);
            await context.PostAsync(messageActivity);
            context.Done(this);
        }
    }
}

QnAMakerServiceAttribute 包含元数据过滤器,但它是一个列表,我的理解是您不能将列表添加到属性。

QnAMakerServiceAttribute.cs

using QnAMakerDialog.Models;
using System;
using System.Collections.Generic;

namespace QnAMakerDialog
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
    [Serializable]
    public class QnAMakerServiceAttribute : Attribute
    {
        public string BaseUri { get; set; }

        public string EndpointKey { get; set; }

        public string KnowledgeBaseId { get; set; }

        public int MaxAnswers { get; set; }

        public List<Metadata> MetadataBoost { get; set; }

        public List<Metadata> MetadataFilter { get; set; } 

        public QnAMakerServiceAttribute(string baseUri, string endpointKey, string knowledgeBaseId, int maxAnswers = 5)
        {
            this.BaseUri = baseUri;
            this.MaxAnswers = maxAnswers;
            this.EndpointKey = endpointKey;
            this.KnowledgeBaseId = knowledgeBaseId;
        }

   }
}

【问题讨论】:

    标签: c# botframework qnamaker


    【解决方案1】:

    尝试将元数据过滤器传递给我的 QnAMakerDialog 请求,但不知道该怎么做。

    您可以参考以下代码 sn-p 为您的 QnADialog 指定MetadataFilter

    var qnaDialog = new QnADialog()
    {
        MetadataFilter = new List<Metadata>()
        {
            new Metadata()
            {
                Name = "filter",
                Value = filterValue
            }
        }
    };
    
    await context.Forward(qnaDialog, AfterQnADialog, messageToForward, CancellationToken.None);
    

    上面的代码对我有用,如果使用 fiddler 捕获请求,我们可以发现请求正文包含“strictFilters”:

    【讨论】:

    • 这是我从提琴手 POST 数据{ "question": "what is fte", "top": 5, "strictFilters": [], "metadataBoost": [], "userId": "QnAMakerDialog" }得到的
    • 我的严格过滤器是空的
    • 您的 _metadataFilter 代码不适用于您的 QnADialog。您可以像我在回复中所做的那样修改您的代码吗?
    • 成功了,谢谢,我在修改以匹配你的时候有一个错字
    猜你喜欢
    • 2020-02-14
    • 2020-01-25
    • 1970-01-01
    • 2015-11-24
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多