本文介绍了未提供有效的KnowledgeBaseId和SubscriptionKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在迁移到新的QNAMaker之后,我需要帮助,现在出现错误:未提供有效的KnowledgeBaseId和SubscriptionKey.使用QnAMakerServiceAttribute或在QnAMakerDialog上设置字段.我想念什么?订阅密钥和KnowledgebaseID已添加.我只是按照示例在qnamaker门户中发布http请求.

I need help, after migrating to the new QNAMaker, im now getting an error: Valid KnowledgeBaseId and SubscriptionKey not provided. Use QnAMakerServiceAttribute or set fields on QnAMakerDialog. What am i missing? Subscription Key and KnowledgebaseID was already added. I simply followed the sample http request upong publishing in the qnamaker portal.

using Microsoft.Bot.Builder.Dialogs;
using QnAMakerDialog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
using Microsoft.Bot.Connector;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.CognitiveServices.QnAMaker;

namespace TEST.Dialog
{
[Serializable]

[QnAMaker(authKey:"013ffd97-XXXX-XXXX-981f-ea298085591c", knowledgebaseId:"f81ce668-XXXX-XXXX-XXXX-ad20c5f4d3fa", endpointHostName:"https://XXXX.azurewebsites.net/qnamaker")]
public class QnADialog : QnAMakerDialog<object>
{
   public async Task StartAsync(IDialogContext context)
    {
        context.PrivateConversationData.TryGetValue("Name", out name);
        await context.PostAsync($"Hello {name}. The QnA Dialog was started. Ask a question.");
        context.Wait(MessageReceivedAsync);

    }

    public async Task DefaultMatchHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
    {
        try
        {
            // ProcessResultAndCreateMessageActivity will remove any attachment markup from the results answer
            // and add any attachments to a new message activity with the message activity text set by default
            // to the answer property from the result
           // var messageActivity = ProcessResultAndCreateMessageActivity(context, ref result);
            if (result.Score > 30 && result.Answer != NOMATCH)
            {
                await context.PostAsync(result.Answer);
                context.Wait(this.MessageReceived);
                return;
            }
            else
            {
                await context.Forward(new RootLuisDialog(), DialogsCompleted, context.Activity, CancellationToken.None);
            }
        }
        catch (Exception ex)
        {
            throw;
        }

    }

    public override async Task NoMatchHandler(IDialogContext context, string originalQueryText)
    {
        try
        {
            await context.Forward(new RootLuisDialog(), DialogsCompleted, context.Activity, CancellationToken.None);
        }
        catch (Exception ex)
        {
            throw;
        }

    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;

        // calculate something for us to return
        int length = (activity.Text ?? string.Empty).Length;

        // return our reply to the user
        //await context.PostAsync($"You sent {activity.Text} which was {length} characters");

        context.Wait(this.MessageReceived);
        return;
    }

     private async Task DialogsCompleted(IDialogContext context, IAwaitable<object> result)
    {
        var success = await result;
        //if (!(bool)success)
        //    await context.PostAsync("I'm sorry. I didn't understand you.");

        //context.UserData.Clear();
        context.Wait(MessageReceived);
    }


    [QnAMakerResponseHandler(30)]
    public async Task LowScoreHandler(IDialogContext context, string originalQueryText, QnAMakerResult result)
    {
        //await context.PostAsync($"I found an answer that might help: {result.Answer}");
        await context.Forward(new RootLuisDialog(), DialogsCompleted, context.Activity, CancellationToken.None);
        //context.Wait(MessageReceived);
    }
}
}

调用QNAMaker的RootDialog:

using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.FormFlow;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;

namespace Test.Dialog
{
[Serializable]
public class RootDialog : IDialog<object>
{
    public string name = string.Empty;
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);
        return Task.CompletedTask;
    }


     private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        try
       {
            //Some User Code that retreives user via PrivateConversationData




            //Calls QNADialog

            context.Call(new QnADialog(), MessageReceivedAsync);
       }
}

}

我的CognitiveServices版本:Microsoft.Bot.Builder.CognitiveServices.1.1.7Bot Builder,Bot连接器:3.15.2.2QNADialog:1.2.0

My Version of CognitiveServices:Microsoft.Bot.Builder.CognitiveServices.1.1.7Bot Builder,Bot Connector :3.15.2.2QNADialog: 1.2.0

推荐答案

似乎您正在使用 QnAMakerDialog 和QnA Maker服务v4.0,但在NuGet包 QnAMakerDialog 和 QnAMakerDialog(已更新为可与QnA Maker v3 API一起使用)的GitHub自述文件 ,我们会发现此QnAMakerDialog块软件包可以与vn的QnA Maker API一起使用,而不是QnA Maker服务v4.0.

It seems that you are using QnAMakerDialog with QnA Maker service v4.0, but in description of NuGet package QnAMakerDialog and GitHub readme of QnAMakerDialog (updated to work with QnA Maker v3 API), we can find that this QnAMakerDialog nugget package can work with v3 of the QnA Maker API, not QnA Maker service v4.0.

如Nicolas R所述,要使用QnA Maker服务v4.0,可以使用以下NuGet软件包: Microsoft.Bot.Builder.CognitiveServices 来创建您的QnAMakerDialog.

To work with QnA Maker service v4.0, as Nicolas R said, you can use this NuGet package: Microsoft.Bot.Builder.CognitiveServices to create your QnAMakerDialog.

[Serializable]
public class QnADialog : QnAMakerDialog
{
    public QnADialog() : base(new QnAMakerService(new QnAMakerAttribute("{qnaAuthKey_here}", " {knowledgebaseId_here}", "No good match in FAQ.", 0.5, 1, "https://xxxx.azurewebsites.net/qnamaker")))
    { }

    //other code logic
}

这篇关于未提供有效的KnowledgeBaseId和SubscriptionKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 04:14