代码之家  ›  专栏  ›  技术社区  ›  anonymous1110

未提供有效的知识库ID和订阅密钥

  •  1
  • anonymous1110  · 技术社区  · 6 年前

    我需要帮助,在迁移到新的Qnamaker之后,我现在得到一个错误:没有提供有效的知识库ID和订阅密钥。使用qnamakerserviceattribute或在qnamakerdialog上设置字段。我错过了什么?已添加订阅密钥和知识库ID。我只是按照Qnamaker门户中的示例HTTP请求upong发布。

    enter image description here

    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);
           }
    }
    

    }

    我的认知服务版本: Microsoft.Bot.Builder.CognitiveServices.1.1.7版 Bot Builder,Bot连接器:3.15.2.2 QN对话框:1.2.0

    2 回复  |  直到 6 年前
        1
  •  0
  •   Fei Han    6 年前

    你好像在用 QnAMakerDialog 使用QNA Maker Service v4.0,但在Nuget包的描述中 Qnamakerdialog公司 和Github自述 QnAMakerDialog (updated to work with QnA Maker v3 API) 我们可以发现,这个Qnamakerdialognugget包可以与qna maker api的v3一起工作,而不是qna maker服务v4.0。

    如Nicolas R所说,要使用QNA Maker Service v4.0,您可以使用此Nuget包: Microsoft.Bot.Builder.CognitiveServices 创建你的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
    }
    
        2
  •  4
  •   Nicolas R    6 年前

    如一般公告中所述,您仍然可以使用 Microsoft.Bot.Builder.CognitiveServices 代码中的包:代码已更改为处理bot v1到v3调用和新v4(GA版本)。

    您只需添加必要的信息,即端点主机名 和以前一样,它是在微软端托管的。

    因此,您的对话框代码如下所示(请参见Github官方示例 here ):

    [Serializable]
    [QnAMaker("set yout authorization key here", "set your kbid here", <score threshold>, <number of results>, "endpoint hostname")]
    public class SimpleQnADialog : QnAMakerDialog
    {
    }