'QNAMaker GetAnswer API with Custom question answering
I have a chatbot setup with QNAMaker and a custom c# bot to query knowledge base. Bot builder 4.2 package is being used. Below is the typical QNAMaker KB details and this works.
Below is the details in c# bot chatbot.bot file. Details have been added from the above
{
"type": "qna",
"KbId": "13xxx-xxx-xxx-xx",
"endpointKey": "89xxx-xxxx-xxx",
"hostname": "https://xxx.azurewebsites.net/qnamaker",
"id": "117",
"name": "QnAMaker-en",
"subscriptionKey": ""
},
Get answer is called in the bot as shown below. More details here
var response = await _service.GetAnswersAsync(stepContext.Context).ConfigureAwait(false);
The above works, with response always has answer from QNAMaker KB.
Recently i plan to use Custom Question Answering. I have created a Knowledge base with Text analytics. After i published this Knowledge base i see the different key to access. Below is the details
I no longer see the Endpoint key instead i get a Ocp-Apim-Subscription-Key. How do make use of this new KB in existing bot. What change is needed in chatbot.bot file? When i try to use Ocp-Apim-Subscription-Key as Endpoint key in chatbot.bot file the GetAnswer response is always null.
{
"type": "qna",
"KbId": "78xxx-xxx-xxx",
"endpointKey": "8exxxxx",
"hostname": "https://xxxxxx.cognitiveservices.azure.com/qnamaker/v5.0-preview.2",
"id": "117",
"name": "QnAMaker-en",
"subscriptionKey": "8exxxxx"
},
Solution 1:[1]
Incase anyone needs it, i went with Custom Question Answering SDK (Azure.AI.Language.QuestionAnswering).
Uri endpoint = new Uri("https://{YOUR-ENDPOINT}.api.cognitive.microsoft.com/");
AzureKeyCredential credential = new AzureKeyCredential("{YOUR-LANGUAGE-RESOURCE-KEY}");
string projectName = "{YOUR-PROJECT-NAME}";
string deploymentName = "production";
string question = "How long should my Surface battery last?";
QuestionAnsweringClient client = new QuestionAnsweringClient(endpoint, credential);
QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
Response<AnswersResult> response = client.GetAnswers(question, project);
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
{
Console.WriteLine($"Q:{question}");
Console.WriteLine($"A:{answer.Answer}");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | prvn |


