首页 > 解决方案 > Azure QnA Maker 认知服务:以编程方式将知识库连接到 QnA Maker

问题描述

如果我通过 Azure 门户创建新知识库,则需要我将现有的 QnA Maker 服务连接到它。

然而,似乎没有一种编程方式来做到这一点:

QnA Maker REST API 提供创建和发布知识库的调用,但是没有关于如何指定要使用的 QnAmaker 服务的信息:

https://docs.microsoft.com/en-us/rest/api/cognitiveservices/qnamaker/knowledgebase

我使用大致以下操作创建和发布知识库,但似乎找不到任何方法将新创建的知识库与现有的 QnA Maker 认知服务相关联。

我是否误解了这两个资源之间的关系,或者这是文档中的一个空白,如果是这样,我如何将新的 kbase 连接到现有的 QnA Maker 服务实例?


function create_kb () {

 userId=$(curl -s -X POST "${api_create_end_point}" \
  -H "Content-Type: application/json" \
  -H "Ocp-Apim-Subscription-Key: ${subscription_key}" \
  --data-ascii "${body}" | jq -r '.userId')

}

function get_user_kbases () {

  kbId=$(curl -s -X GET "https://${endpoint}/qnamaker/v4.0/knowledgebases" \
    -H "Ocp-Apim-Subscription-Key: ${subscription_key}" \
    --data-ascii "" | jq -r '.knowledgebases | .[] | select(.name == "govbotkb").id')
  echo "${kbId}"
}


function publish_knowledge_base () {

  echo "Publishing the knowledgebase ${kbId} ..."

  publish_result=$(curl -s -X POST "https://${endpoint}/qnamaker/v4.0/knowledgebases/${kbId}" \
    -H "Ocp-Apim-Subscription-Key: ${subscription_key}" \
    --data-ascii "${body}")

  echo "${publish_result}"

}


function get_knowledgebase_details () {

   echo "Getting knowledgebase details ..."
   echo curl -v -X GET "https://${endpoint}/qnamaker/v4.0/knowledgebases/${kbId}" -H "Ocp-Apim-Subscription-Key: ${subscription_key}"
   kbase_details=$( curl -s -X GET "https://${endpoint}/qnamaker/v4.0/knowledgebases/${kbId}" \
                   -H "Ocp-Apim-Subscription-Key: ${subscription_key}" \
                   --data-ascii "{body}"
                  )
    echo "${kbase_details}"

}

标签: bashazurecurlazure-cognitive-servicesqnamaker

解决方案


You are passing a subscription key into each of those API calls, including when you create the knowledge base. The subscription key comes from your QnA service, and so it is used to identify your service and connect the knowledge base to it.


推荐阅读