您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.
快速入门:通过 Python 在 QnA Maker 中创建知识库Quickstart: Create a knowledge base in QnA Maker using Python
12/16/2019
本文内容
本快速入门将指导你完成以编程方式创建和发布示例 QnA Maker 知识库的过程。This quickstart walks you through programmatically creating and publishing a sample QnA Maker knowledge base. QnA Maker 自动从数据源中从半结构化内容(例如常见问题解答)中自动提取问题和解答。QnA Maker automatically extracts questions and answers from semi-structured content, like FAQs, from data sources. 用于知识库的模型是在 API 请求的正文中发送的 JSON 中定义的。The model for the knowledge base is defined in the JSON sent in the body of the API request.
本快速入门调用了 QnA Maker API:This quickstart calls QnA Maker APIs:
备注
2019 年 7 月 1 日之后创建的新资源将使用自定义子域名。New resources created after July 1, 2019, will use custom subdomain names. 有关详细信息和区域终结点的完整列表,请参阅认知服务的自定义子域名。For more information and a complete list of regional endpoints, see Custom subdomain names for Cognitive Services.
先决条件Prerequisites
若要检索密钥和终结点(包括资源名称),请在 Azure 门户中为资源选择“快速入门”。To retrieve your key and endpoint (which includes the resource name), select Quickstart for your resource in the Azure portal.
创建知识库 Python 文件Create a knowledge base Python file
创建名为 create-new-knowledge-base-3x.py 的文件。Create a file named create-new-knowledge-base-3x.py.
添加必需的依赖项Add the required dependencies
在 create-new-knowledge-base-3x.py 的顶部,添加以下行来向项目添加必需的依赖项:At the top of create-new-knowledge-base-3x.py, add the following lines to add necessary dependencies to the project:
import http.client, json, os, time
from urllib.parse import urlparse
添加必需的常量Add the required constants
在上述必需的依赖项后,添加访问 QnA Maker 所必需的常量。After the preceding required dependencies, add the required constants to access QnA Maker. 将 和 的值替换为你自己的 QnA Maker 密钥和资源名称。Replace the value of the and with your own QnA Maker key and resource name.
在 Program 类的顶部,