I am programmatically building a QnA using C#. I want to programmatically obtain the answer of a question, to do so, I have used the documentation provided by Microsoft in the following link:
https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/csharp#GetAnswers
However, if I follow the instructions there:
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();
}
}
}
Rather than getting an answer, I am getting a resource not found. While the others methods as update the knowledge base, work well with the same uri, does anybody know why is this happening?