如何在 QnA Maker v4.0 中以编程方式获取一对的 id?
Posted
技术标签:
【中文标题】如何在 QnA Maker v4.0 中以编程方式获取一对的 id?【英文标题】:How to programmatically get the id of a pair in QnA Maker v4.0? 【发布时间】:2019-01-04 13:10:48 【问题描述】:我正在使用 C# 以编程方式构建 QnA。我想以编程方式获取问题的答案,为此,我使用了 Microsoft 在以下链接中提供的文档:
https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/csharp#GetAnswers
但是,如果我按照那里的说明进行操作:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace QnAMaker
class Program
// NOTE: Replace this with a valid host name.
static string host = "ENTER HOST HERE";
// NOTE: Replace this with a valid endpoint key.
// This is not your subscription key.
// To get your endpoint keys, call the GET /endpointkeys method.
static string endpoint_key = "ENTER KEY HERE";
// NOTE: Replace this with a valid knowledge base ID.
// Make sure you have published the knowledge base with the
// POST /knowledgebases/knowledge base ID method.
static string kb = "ENTER KB ID HERE";
static string service = "/qnamaker";
static string method = "/knowledgebases/" + kb + "/generateAnswer/";
static string question = @"
'question': 'Is the QnA Maker Service free?',
'top': 3
";
async static Task<string> Post(string uri, string body)
using (var client = new HttpClient())
using (var request = new HttpRequestMessage())
request.Method = HttpMethod.Post;
request.RequestUri = new Uri(uri);
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
request.Headers.Add("Authorization", "EndpointKey " + endpoint_key);
var response = await client.SendAsync(request);
return await response.Content.ReadAsStringAsync();
async static void GetAnswers()
var uri = host + service + method;
Console.WriteLine("Calling " + uri + ".");
var response = await Post(uri, question);
Console.WriteLine(response);
Console.WriteLine("Press any key to continue.");
static void Main(string[] args)
GetAnswers();
Console.ReadLine();
我没有得到答案,而是得到了一个未找到的资源。虽然其他方法作为更新知识库,在相同的 uri 上运行良好,但有人知道为什么会发生这种情况吗?
【问题讨论】:
【参考方案1】:这是因为 API 的某些端点不是通用的,而是暴露在您身边的主机上。
正如文档所说,Replace the host value with the Website name for your QnA Maker subscription
: 主机不是https://westus.api.cognitive.microsoft.com/...
架构如下,您要查找的端点位于绿色一侧,而不是蓝色一侧:
这也是您在文档https://westus.dev.cognitive.microsoft.com/docs/services/5a93fcf85b4ccd136866eb37/operations/5ac266295b4ccd1554da75ff 上找不到generateAnswer
的原因
所以转到https://www.qnamaker.ai/Home/MyServices,单击您的 QnA KB,如果尚未完成,请发布它,然后在设置中您将获得如下有趣的详细信息:
【讨论】:
以上是关于如何在 QnA Maker v4.0 中以编程方式获取一对的 id?的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Analytics Application Insights 获取 Qna Maker“Q”?