gpt4 book ai didi

c# - 未提供有效的 KnowledgeBaseId 和 SubscriptionKey

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:11 24 4
gpt4 key购买 nike

我需要帮助,迁移到新的 QNAMaker 后,我现在收到错误:未提供有效的 KnowledgeBaseId 和 SubscriptionKey。使用 QnAMakerServiceAttribute 或在 QnAMakerDialog 上设置字段。我缺少什么?订阅 key 和知识库ID 已添加。我只是按照在 qnamaker 门户中发布的示例 http 请求进行操作。

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机器人生成器、机器人连接器:3.15.2.2QNADialog:1.2.0

最佳答案

正如公开公告中所解释的,您仍然可以在代码中使用 Microsoft.Bot.Builder.CognitiveServices 包:代码已更改为处理机器人 v1 到 v3 调用以及新的 v4 ( GA 版本)。

您只需添加必要的信息,即端点主机名,因为它以前托管在 Microsoft 端。

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

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

关于c# - 未提供有效的 KnowledgeBaseId 和 SubscriptionKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50445723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com