QNAMaker GetAnswer API 与自定义问答
QNAMaker GetAnswer API with Custom question answering
我使用 QNAMaker 设置了一个聊天机器人和一个用于查询知识库的自定义 C# 机器人。正在使用 Bot builder 4.2 包。以下是典型的 QNAMaker 知识库详细信息,并且有效。
以下是 c# bot chatbot.bot 文件中的详细信息。从上面添加了详细信息
{
"type": "qna",
"KbId": "13xxx-xxx-xxx-xx",
"endpointKey": "89xxx-xxxx-xxx",
"hostname": "https://xxx.azurewebsites.net/qnamaker",
"id": "117",
"name": "QnAMaker-en",
"subscriptionKey": ""
},
获取答案在机器人中调用,如下所示。更多详情 here
var response = await _service.GetAnswersAsync(stepContext.Context).ConfigureAwait(false);
以上有效,响应总是有来自 QNAMaker KB 的答案。
最近打算使用自定义问答。我创建了一个带有文本分析的知识库。在我发布此知识库后,我看到了不同的访问密钥。以下是详情
我不再看到终结点密钥,而是获得了一个 Ocp-Apim-Subscription-Key。如何在现有机器人中使用这个新的 KB。 chatbot.bot 文件需要做哪些更改?当我尝试使用 Ocp-Apim-Subscription-Key 作为 chatbot.bot 文件中的端点键时,GetAnswer 响应始终为空。
{
"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"
},
BotFramework SDK 尚不支持新的自定义问题功能。这个。功能请求已在 github 中提交:https://github.com/microsoft/botframework-sdk/issues/6413
万一有人需要,我选择了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}");
}
我使用 QNAMaker 设置了一个聊天机器人和一个用于查询知识库的自定义 C# 机器人。正在使用 Bot builder 4.2 包。以下是典型的 QNAMaker 知识库详细信息,并且有效。
以下是 c# bot chatbot.bot 文件中的详细信息。从上面添加了详细信息
{
"type": "qna",
"KbId": "13xxx-xxx-xxx-xx",
"endpointKey": "89xxx-xxxx-xxx",
"hostname": "https://xxx.azurewebsites.net/qnamaker",
"id": "117",
"name": "QnAMaker-en",
"subscriptionKey": ""
},
获取答案在机器人中调用,如下所示。更多详情 here
var response = await _service.GetAnswersAsync(stepContext.Context).ConfigureAwait(false);
以上有效,响应总是有来自 QNAMaker KB 的答案。
最近打算使用自定义问答。我创建了一个带有文本分析的知识库。在我发布此知识库后,我看到了不同的访问密钥。以下是详情
我不再看到终结点密钥,而是获得了一个 Ocp-Apim-Subscription-Key。如何在现有机器人中使用这个新的 KB。 chatbot.bot 文件需要做哪些更改?当我尝试使用 Ocp-Apim-Subscription-Key 作为 chatbot.bot 文件中的端点键时,GetAnswer 响应始终为空。
{
"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"
},
BotFramework SDK 尚不支持新的自定义问题功能。这个。功能请求已在 github 中提交:https://github.com/microsoft/botframework-sdk/issues/6413
万一有人需要,我选择了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}");
}