使用健康状况文本分析容器

使用容器,你可以将健康状况文本分析 API 托管在自己的基础结构上。 如果你的安全要求或数据管理要求不能通过远程调用健康状况文本分析来完成,则容器可能是一个不错的选择。

如果没有 Azure 订阅,可在开始前创建一个试用帐户

先决条件

使用健康状况文本分析容器之前,必须满足以下先决条件。 如果没有 Azure 订阅,可在开始前创建一个试用帐户

  • 在主计算机上安装的 Docker。 必须将 Docker 配置为允许容器连接 Azure 并向其发送账单数据。
    • 在 Windows 上,还必须将 Docker 配置为支持 Linux 容器。
    • 应基本了解 Docker 概念
  • 使用免费 (F0) 或标准 (S) 定价层语言资源

收集必需的参数

所有 Azure AI 容器都需要三个主要参数。 Microsoft 软件许可条款的值必须为 accept。 还需要终结点 URI 和 API 密钥。

终结点 URI

可在 Azure 门户中相应 Azure AI 服务资源的“概览”页上找到 {ENDPOINT_URI} 值。 转到“概述”页,将鼠标悬停在终结点上就会显示一个“复制到剪贴板”图标。 在需要的地方复制并使用终结点。

屏幕截图显示如何收集终结点 URI 以供将来使用。

{API_KEY} 值用于启动容器,可在 Azure 门户中相应 Azure AI 服务资源的“密钥”页上找到。 转到“密钥”页,选择“复制到剪贴板” 图标。

屏幕截图显示如何获取两个密钥之一以供将来使用。

重要

这些订阅密钥用于访问 Azure AI 服务 API。 请勿共享密钥。 安全地存储它们。 例如,使用 Azure Key Vault。 此外,建议定期重新生成这些密钥。 发出 API 调用只需一个密钥。 重新生成第一个密钥时,可以使用第二个密钥继续访问服务。

主机要求和建议

主机是运行 Docker 容器且基于 x64 的计算机。 它可以是本地计算机或 Azure 中的 Docker 托管服务,例如:

下表显示了健康状况文本分析容器的最小和建议的资源规范。 每个 CPU 核心必须至少为 2.6 千兆赫 (GHz) 或更快。 还列出了允许的每秒事务数 (TPS)。

最小主机规格 推荐主机规格 最小 TPS 最大 TPS
1 个文档/请求 4 核,12GB 内存 6 核,12GB 内存 15 30
10 个文档/请求 6 核,16GB 内存 8 核,20GB 内存 15 30

CPU 核心和内存对应于 --cpus--memory 设置,用作 docker run 命令的一部分。

使用 docker pull 获取容器映像

mcr.microsoft.com 容器注册表联合项中可以找到运行状况文本分析容器映像。 该映像驻留在 azure-cognitive-services/textanalytics/ 存储库中,名为 healthcare。 完全限定的容器映像名称为 mcr.microsoft.com/azure-cognitive-services/textanalytics/healthcare

若要使用最新版本的容器,可以使用 latest 标记。 还可以在 MCR 上找到标记的完整列表

使用 docker pull 命令从 Microsoft 公共容器注册表下载此容器映像。 可以在 Microsoft 容器注册表上找到特色标记

docker pull mcr.microsoft.com/azure-cognitive-services/textanalytics/healthcare:<tag-name>

提示

可以使用 docker images 命令列出下载的容器映像。 例如,以下命令以表格列出每个下载的容器映像的 ID、存储库和标记:

docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

IMAGE ID            REPOSITORY              TAG
<image-id>       <repository-path/name>     <tag-name>

通过 docker run 运行容器

一旦容器位于主机上,请使用 docker run 命令运行容器。 容器将继续运行,直到停止它。

重要

  • 以下各节中的 docker 命令使用反斜杠 \ 作为行继续符。 根据主机操作系统的要求替换或删除字符。
  • 必须指定 EulaBillingApiKey 选项运行容器;否则,该容器不会启动。 有关详细信息,请参阅计费
    • 负责任 AI (RAI) 确认也必须以 accept 的值呈现。
  • 情绪分析和语言检测容器使用该 API 的 v3 版本,并且已正式发布。 关键短语提取容器使用该 API 的 v2 版本,并且处于预览阶段。

可以通过多种方式来安装和运行运行状况文本分析容器。

  • 使用 Azure 门户创建语言资源,并使用 Docker 获取容器。
  • 使用带有 Docker 的 Azure VM 运行容器。
  • 使用以下 PowerShell 和 Azure CLI 脚本自动执行资源部署和容器配置。

使用运行状况文本分析容器时,API 请求和响应中包含的数据对 Microsoft 不可见,并且不用于训练应用到你的数据的模型。

在本地运行容器

若要在下载容器映像后在自己的环境中运行容器,请执行以下 docker run 命令。 将下面的占位符替换为你自己的值:

占位符 Value 格式或示例
{API_KEY} 语言资源的密钥。 可以在 Azure 门户中资源的“密钥和终结点”页上找到此项。 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{ENDPOINT_URI} 用于访问 API 的终结点。 可以在 Azure 门户中资源的“密钥和终结点”页上找到此项。 https://<your-custom-subdomain>.cognitiveservices.azure.cn
docker run --rm -it -p 5000:5000 --cpus 6 --memory 12g \
mcr.microsoft.com/azure-cognitive-services/textanalytics/healthcare:<tag-name> \
Eula=accept \
rai_terms=accept \
Billing={ENDPOINT_URI} \
ApiKey={API_KEY} 

此命令:

  • 从容器映像运行“针对运行状况的文本分析”容器
  • 分配 6 个 CPU 核心和 12 千兆字节 (GB) 内存
  • 公开 TCP 端口 5000,并为容器分配伪 TTY
  • 接受最终用户许可协议 (EULA) 和负责任 AI (RAI) 条款
  • 退出后自动删除容器。 容器映像在主计算机上仍然可用。

用于可视化输出的演示 UI

容器提供了基于 REST 的查询预测终结点 API。 我们还在容器中提供了一个可视化工具,通过将 /demo 追加到容器的终结点,可以访问该工具。 例如:

http://<serverURL>:5000/demo

使用下面的示例 cURL 请求将查询提交到已部署的容器,并使用适当的值替换 serverURL 变量。

curl -X POST 'http://<serverURL>:5000/text/analytics/v3.1/entities/health' --header 'Content-Type: application/json' --header 'accept: application/json' --data-binary @example.json

使用 Azure 用于容器的 Web 应用安装容器

Azure 用于容器的 Web 应用是专用于在云中运行容器的 Azure 资源。 它提供自动缩放、Docker 容器和 Docker 编写支持、HTTPS 支持等开箱即用功能。

注意

使用 Azure Web 应用时,将自动获取 <appservice_name>.chinacloudsites.cn 格式的域

通过 HTTPS 使用订阅和容器映像,从而利用 Azure CLI 运行此 PowerShell 脚本来创建用于容器的 Web 应用。 等待脚本完成(大约 25-30 分钟),然后提交第一个请求。

$subscription_name = ""                    # THe name of the subscription you want you resource to be created on.
$resource_group_name = ""                  # The name of the resource group you want the AppServicePlan
                                           #    and AppSerivce to be attached to.
$resources_location = ""                   # This is the location you wish the AppServicePlan to be deployed to.
                                           #    You can use the "az account list-locations -o table" command to
                                           #    get the list of available locations and location code names.
$appservice_plan_name = ""                 # This is the AppServicePlan name you wish to have.
$appservice_name = ""                      # This is the AppService resource name you wish to have.
$TEXT_ANALYTICS_RESOURCE_API_KEY = ""      # This should be taken from the Language resource.
$TEXT_ANALYTICS_RESOURCE_API_ENDPOINT = "" # This should be taken from the Language resource.
$DOCKER_IMAGE_NAME = "mcr.microsoft.com/azure-cognitive-services/textanalytics/healthcare:latest"

az login
az account set -s $subscription_name
az appservice plan create -n $appservice_plan_name -g $resource_group_name --is-linux -l $resources_location --sku P3V2
az webapp create -g $resource_group_name -p $appservice_plan_name -n $appservice_name -i $DOCKER_IMAGE_NAME 
az webapp config appsettings set -g $resource_group_name -n $appservice_name --settings Eula=accept rai_terms=accept Billing=$TEXT_ANALYTICS_RESOURCE_API_ENDPOINT ApiKey=$TEXT_ANALYTICS_RESOURCE_API_KEY

# Once deployment complete, the resource should be available at: https://<appservice_name>.chinacloudsites.cn

使用 Azure 容器实例安装容器

还可以使用 Azure 容器实例 (ACI) 更轻松地部署。 ACI 资源允许在托管的无服务器 Azure 环境中按需运行 Docker 容器。

有关使用 Azure 门户部署 ACI 资源的步骤,请参阅如何使用 Azure 容器实例。 还可以通过 Azure CLI 使用以下 PowerShell 脚本,这将使用容器映像在订阅上创建 ACI。 等待脚本完成(大约 25-30 分钟),然后提交第一个请求。 由于每个 ACI 资源的最大 CPU 数的限制,如果你希望每个请求提交 5 个以上的大型文档(每个文档大约 5000 个字符),请不要选择此选项。 请参阅 ACI 区域支持文章,获取可用性信息。

注意

Azure 容器实例不包括对内置域的 HTTPS 支持。 如果需要 HTTPS,则需要手动配置它,包括创建证书和注册域。 可以通过下面的 NGINX 查找有关如何执行此操作的说明。

$subscription_name = ""                    # The name of the subscription you want you resource to be created on.
$resource_group_name = ""                  # The name of the resource group you want the AppServicePlan
                                           # and AppService to be attached to.
$resources_location = ""                   # This is the location you wish the web app to be deployed to.
                                           # You can use the "az account list-locations -o table" command to
                                           # Get the list of available locations and location code names.
$azure_container_instance_name = ""        # This is the AzureContainerInstance name you wish to have.
$TEXT_ANALYTICS_RESOURCE_API_KEY = ""      # This should be taken from the Language resource.
$TEXT_ANALYTICS_RESOURCE_API_ENDPOINT = "" # This should be taken from the Language resource.
$DNS_LABEL = ""                            # This is the DNS label name you wish your ACI will have
$DOCKER_IMAGE_NAME = "mcr.microsoft.com/azure-cognitive-services/textanalytics/healthcare:latest"

az login
az account set -s $subscription_name
az container create --resource-group $resource_group_name --name $azure_container_instance_name --image $DOCKER_IMAGE_NAME --cpu 4 --memory 12 --port 5000 --dns-name-label $DNS_LABEL --environment-variables Eula=accept rai_terms=accept Billing=$TEXT_ANALYTICS_RESOURCE_API_ENDPOINT ApiKey=$TEXT_ANALYTICS_RESOURCE_API_KEY

# Once deployment complete, the resource should be available at: http://<unique_dns_label>.<resource_group_region>.azurecontainer.io:5000

保护 ACI 连接

默认情况下,将 ACI 与容器 API 一起使用时不提供安全性。 这是因为大多数情况下容器会作为 Pod 的一部分运行,而 Pod 受网络桥的保护,与外部隔离。 但是,可以使用前端组件来修改容器,使容器终结点保持专用。 以下示例使用 NGINX 作为入口网关,以支持 HTTPS/SSL 和客户端证书身份验证。

注意

NGINX 是高性能的开源 HTTP 服务器和代理。 NGINX 容器可用于终止单个容器的 TLS 连接。 还可能会有更复杂的基于 NGINX 入口的 TLS 终止解决方案。

将 NGINX 设置为入口网关

NGINX 使用配置文件在运行时启用功能。 若要为另一个服务启用 TLS 终止,必须指定用于终止 TLS 连接的 SSL 证书,以及用于指定服务地址的 proxy_pass。 下面提供了示例。

注意

ssl_certificate 需要路径在 NGINX 容器的本地文件系统中进行指定。 为 proxy_pass 指定的地址必须在 NGINX 容器的网络中可用。

NGINX 容器将 /etc/nginx/conf.d/ 下装载的 _.conf_ 中的所有文件加载到 HTTP 配置路径。

server {
  listen              80;
  return 301 https://$host$request_uri;
}
server {
  listen              443 ssl;
  # replace with .crt and .key paths
  ssl_certificate     /cert/Local.crt;
  ssl_certificate_key /cert/Local.key;

  location / {
    proxy_pass http://cognitive-service:5000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP  $remote_addr;
  }
}

示例 Docker compose 文件

以下示例演示了如何创建 Docker Compose 文件来部署 NGINX 和健康状况容器:

version: "3.7"
services:
  cognitive-service:
    image: {IMAGE_ID}
    ports:
      - 5000:5000
    environment:
      - eula=accept
      - billing={ENDPOINT_URI}
      - apikey={API_KEY}
    volumes:
        # replace with path to logs folder
      - <path-to-logs-folder>:/output
  nginx:
    image: nginx
    ports:
      - 443:443
    volumes:
        # replace with paths for certs and conf folders
      - <path-to-certs-folder>:/cert
      - <path-to-conf-folder>:/etc/nginx/conf.d/

若要启动此 Docker compose 文件,请在文件根级别从控制台中执行以下命令:

docker-compose up

有关详细信息,请参阅有关 NGINX SSL 终止的 NGINX 文档。

在同一主机上运行多个容器

若要使用公开端口运行多个容器,请确保在运行每个容器时使用不同的公开端口。 例如,在端口 5000 上运行第一个容器,在端口 5001 上运行第二个容器。

可以让此容器和其他 Azure 认知服务容器一起运行在该主机上。 此外,还可以让同一认知服务容器的多个容器一起运行。

查询容器的预测终结点

容器提供了基于 REST 的查询预测终结点 API。

为容器 API 使用主机 http://localhost:5000

验证容器是否正在运行

有几种方法可用于验证容器是否正在运行。 找到相关容器的外部 IP 地址和公开端口,并打开你常用的 Web 浏览器。 使用以下各种请求 URL 验证容器是否正在运行。 此处列出的示例请求 URL 是 http://localhost:5000,但是你的特定容器可能会有所不同。 请确保依赖容器的外部 IP 地址和公开端口。

请求 URL 用途
http://localhost:5000/ 容器提供主页。
http://localhost:5000/ready 使用 GET 对此 URL 进行请求,可以验证容器是否已准备好接受针对模型的查询。 此请求可用于 Kubernetes 运行情况和就绪情况探测
http://localhost:5000/status 同样使用 GET 对此 URL 进行请求,可以验证用于启动容器的 api-key 是否有效,而不会导致终结点查询。 此请求可用于 Kubernetes 运行情况和就绪情况探测
http://localhost:5000/swagger 容器为终结点提供一组完整的文档以及“尝试”功能。 使用此功能可以将设置输入到基于 Web 的 HTML 表单并进行查询,而无需编写任何代码。 查询返回后,将提供示例 CURL 命令,用于演示所需的 HTTP 标头和正文格式。

容器的主页

为容器构造 API 请求

可以使用 Postman 或下面的 cURL 请求示例向部署的容器提交查询,以适当的值替换 serverURL 变量。 请注意,容器的 URL 中的 API 版本不同于托管 API。

注意

快速医疗保健互操作性资源 (FHIR) 功能在最新容器中可用,并通过新的语言 REST API 公开。

curl -i -X POST 'http://<serverURL>:5000/language/analyze-text/jobs?api-version=2022-04-01-preview' --header 'Content-Type: application/json' --header --data-binary @example.json

以下 JSON 是附加到语言请求的 POST 正文的 JSON 文件示例:

example.json

{
    "analysisInput": {
        "documents": [
            {
                "text": "The doctor prescried 200mg Ibuprofen.",
                "language": "en",
                "id": "1"
            }
        ]
    },
    "tasks": [
        {
            "taskName": "analyze 1",
            "kind": "Healthcare",
            "parameters": {
                "fhirVersion": "4.0.1"
            }
        }
    ]
}

容器响应正文

以下 JSON 是来自容器化同步调用的语言响应正文的示例:

{
  "jobId": "{JOB-ID}",
  "lastUpdateDateTime": "2022-04-18T15:50:16Z",
  "createdDateTime": "2022-04-18T15:50:14Z",
  "expirationDateTime": "2022-04-19T15:50:14Z",
  "status": "succeeded",
  "errors": [],
  "tasks": {
    "completed": 1,
    "failed": 0,
    "inProgress": 0,
    "total": 1,
    "items": [
      {
        "kind": "HealthcareLROResults",
        "taskName": "analyze 1",
        "lastUpdateDateTime": "2022-04-18T15:50:16.7046515Z",
        "status": "succeeded",
        "results": {
          "documents": [
            {
              "id": "1",
              "entities": [
                {
                  "offset": 4,
                  "length": 6,
                  "text": "doctor",
                  "category": "HealthcareProfession",
                  "confidenceScore": 0.76
                },
                {
                  "offset": 21,
                  "length": 5,
                  "text": "200mg",
                  "category": "Dosage",
                  "confidenceScore": 0.99
                },
                {
                  "offset": 27,
                  "length": 9,
                  "text": "Ibuprofen",
                  "category": "MedicationName",
                  "confidenceScore": 1.0,
                  "name": "ibuprofen",
                  "links": [
                    { "dataSource": "UMLS", "id": "C0020740" },
                    { "dataSource": "AOD", "id": "0000019879" },
                    { "dataSource": "ATC", "id": "M01AE01" },
                    { "dataSource": "CCPSS", "id": "0046165" },
                    { "dataSource": "CHV", "id": "0000006519" },
                    { "dataSource": "CSP", "id": "2270-2077" },
                    { "dataSource": "DRUGBANK", "id": "DB01050" },
                    { "dataSource": "GS", "id": "1611" },
                    { "dataSource": "LCH_NW", "id": "sh97005926" },
                    { "dataSource": "LNC", "id": "LP16165-0" },
                    { "dataSource": "MEDCIN", "id": "40458" },
                    { "dataSource": "MMSL", "id": "d00015" },
                    { "dataSource": "MSH", "id": "D007052" },
                    { "dataSource": "MTHSPL", "id": "WK2XYI10QM" },
                    { "dataSource": "NCI", "id": "C561" },
                    { "dataSource": "NCI_CTRP", "id": "C561" },
                    { "dataSource": "NCI_DCP", "id": "00803" },
                    { "dataSource": "NCI_DTP", "id": "NSC0256857" },
                    { "dataSource": "NCI_FDA", "id": "WK2XYI10QM" },
                    { "dataSource": "NCI_NCI-GLOSS", "id": "CDR0000613511" },
                    { "dataSource": "NDDF", "id": "002377" },
                    { "dataSource": "PDQ", "id": "CDR0000040475" },
                    { "dataSource": "RCD", "id": "x02MO" },
                    { "dataSource": "RXNORM", "id": "5640" },
                    { "dataSource": "SNM", "id": "E-7772" },
                    { "dataSource": "SNMI", "id": "C-603C0" },
                    { "dataSource": "SNOMEDCT_US", "id": "387207008" },
                    { "dataSource": "USP", "id": "m39860" },
                    { "dataSource": "USPMG", "id": "MTHU000060" },
                    { "dataSource": "VANDF", "id": "4017840" }
                  ]
                }
              ],
              "relations": [
                {
                  "relationType": "DosageOfMedication",
                  "entities": [
                    {
                      "ref": "#/results/documents/0/entities/1",
                      "role": "Dosage"
                    },
                    {
                      "ref": "#/results/documents/0/entities/2",
                      "role": "Medication"
                    }
                  ]
                }
              ],
              "warnings": [],
              "fhirBundle": {
                "resourceType": "Bundle",
                "id": "bae9d4e0-191e-48e6-9c24-c1ff6097c439",
                "meta": {
                  "profile": [
                    "http://hl7.org/fhir/4.0.1/StructureDefinition/Bundle"
                  ]
                },
                "identifier": {
                  "system": "urn:ietf:rfc:3986",
                  "value": "urn:uuid:bae9d4e0-191e-48e6-9c24-c1ff6097c439"
                },
                "type": "document",
                "entry": [
                  {
                    "fullUrl": "Composition/9044c2cc-dcec-4b9d-b005-bfa8be978aa8",
                    "resource": {
                      "resourceType": "Composition",
                      "id": "9044c2cc-dcec-4b9d-b005-bfa8be978aa8",
                      "status": "final",
                      "type": {
                        "coding": [
                          {
                            "system": "http://loinc.org",
                            "code": "11526-1",
                            "display": "Pathology study"
                          }
                        ],
                        "text": "Pathology study"
                      },
                      "subject": {
                        "reference": "Patient/5c554347-4290-4b05-83ac-6637ff3bfb40",
                        "type": "Patient"
                      },
                      "encounter": {
                        "reference": "Encounter/6fe12f5b-e35c-4c92-a492-96feda5a1a3b",
                        "type": "Encounter",
                        "display": "unknown"
                      },
                      "date": "2022-04-18",
                      "author": [
                        {
                          "reference": "Practitioner/fb5da4d8-e0f0-4434-8d29-4419b065c4d7",
                          "type": "Practitioner",
                          "display": "Unknown"
                        }
                      ],
                      "title": "Pathology study",
                      "section": [
                        {
                          "title": "General",
                          "code": {
                            "coding": [
                              {
                                "system": "",
                                "display": "Unrecognized Section"
                              }
                            ],
                            "text": "General"
                          },
                          "text": {
                            "div": "<div>\r\n\t\t\t\t\t\t\t<h1>General</h1>\r\n\t\t\t\t\t\t\t<p>The doctor prescried 200mg Ibuprofen.</p>\r\n\t\t\t\t\t</div>"
                          },
                          "entry": [
                            {
                              "reference": "List/db388912-b5fb-4073-a74c-2751fd3374dd",
                              "type": "List",
                              "display": "General"
                            }
                          ]
                        }
                      ]
                    }
                  },
                  {
                    "fullUrl": "Practitioner/fb5da4d8-e0f0-4434-8d29-4419b065c4d7",
                    "resource": {
                      "resourceType": "Practitioner",
                      "id": "fb5da4d8-e0f0-4434-8d29-4419b065c4d7",
                      "extension": [
                        {
                          "extension": [
                            { "url": "offset", "valueInteger": -1 },
                            { "url": "length", "valueInteger": 7 }
                          ],
                          "url": "http://hl7.org/fhir/StructureDefinition/derivation-reference"
                        }
                      ],
                      "name": [{ "text": "Unknown", "family": "Unknown" }]
                    }
                  },
                  {
                    "fullUrl": "Patient/5c554347-4290-4b05-83ac-6637ff3bfb40",
                    "resource": {
                      "resourceType": "Patient",
                      "id": "5c554347-4290-4b05-83ac-6637ff3bfb40",
                      "gender": "unknown"
                    }
                  },
                  {
                    "fullUrl": "Encounter/6fe12f5b-e35c-4c92-a492-96feda5a1a3b",
                    "resource": {
                      "resourceType": "Encounter",
                      "id": "6fe12f5b-e35c-4c92-a492-96feda5a1a3b",
                      "meta": {
                        "profile": [
                          "http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter"
                        ]
                      },
                      "status": "finished",
                      "class": {
                        "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
                        "display": "unknown"
                      },
                      "subject": {
                        "reference": "Patient/5c554347-4290-4b05-83ac-6637ff3bfb40",
                        "type": "Patient"
                      }
                    }
                  },
                  {
                    "fullUrl": "MedicationStatement/24e860ce-2fdc-4745-aa9e-7d30bb487c4e",
                    "resource": {
                      "resourceType": "MedicationStatement",
                      "id": "24e860ce-2fdc-4745-aa9e-7d30bb487c4e",
                      "extension": [
                        {
                          "extension": [
                            { "url": "offset", "valueInteger": 27 },
                            { "url": "length", "valueInteger": 9 }
                          ],
                          "url": "http://hl7.org/fhir/StructureDefinition/derivation-reference"
                        }
                      ],
                      "status": "active",
                      "medicationCodeableConcept": {
                        "coding": [
                          {
                            "system": "http://www.nlm.nih.gov/research/umls",
                            "code": "C0020740",
                            "display": "Ibuprofen"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/aod",
                            "code": "0000019879"
                          },
                          {
                            "system": "http://www.whocc.no/atc",
                            "code": "M01AE01"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/ccpss",
                            "code": "0046165"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/chv",
                            "code": "0000006519"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/csp",
                            "code": "2270-2077"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/drugbank",
                            "code": "DB01050"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/gs",
                            "code": "1611"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/lch_nw",
                            "code": "sh97005926"
                          },
                          { "system": "http://loinc.org", "code": "LP16165-0" },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/medcin",
                            "code": "40458"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/mmsl",
                            "code": "d00015"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/msh",
                            "code": "D007052"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/mthspl",
                            "code": "WK2XYI10QM"
                          },
                          {
                            "system": "http://ncimeta.nci.nih.gov",
                            "code": "C561"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nci_ctrp",
                            "code": "C561"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nci_dcp",
                            "code": "00803"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nci_dtp",
                            "code": "NSC0256857"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nci_fda",
                            "code": "WK2XYI10QM"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nci_nci-gloss",
                            "code": "CDR0000613511"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/nddf",
                            "code": "002377"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/pdq",
                            "code": "CDR0000040475"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/rcd",
                            "code": "x02MO"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
                            "code": "5640"
                          },
                          {
                            "system": "http://snomed.info/sct",
                            "code": "E-7772"
                          },
                          {
                            "system": "http://snomed.info/sct/900000000000207008",
                            "code": "C-603C0"
                          },
                          {
                            "system": "http://snomed.info/sct/731000124108",
                            "code": "387207008"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/usp",
                            "code": "m39860"
                          },
                          {
                            "system": "http://www.nlm.nih.gov/research/umls/uspmg",
                            "code": "MTHU000060"
                          },
                          {
                            "system": "http://hl7.org/fhir/ndfrt",
                            "code": "4017840"
                          }
                        ],
                        "text": "Ibuprofen"
                      },
                      "subject": {
                        "reference": "Patient/5c554347-4290-4b05-83ac-6637ff3bfb40",
                        "type": "Patient"
                      },
                      "context": {
                        "reference": "Encounter/6fe12f5b-e35c-4c92-a492-96feda5a1a3b",
                        "type": "Encounter",
                        "display": "unknown"
                      },
                      "dosage": [
                        {
                          "text": "200mg",
                          "doseAndRate": [{ "doseQuantity": { "value": 200 } }]
                        }
                      ]
                    }
                  },
                  {
                    "fullUrl": "List/db388912-b5fb-4073-a74c-2751fd3374dd",
                    "resource": {
                      "resourceType": "List",
                      "id": "db388912-b5fb-4073-a74c-2751fd3374dd",
                      "status": "current",
                      "mode": "snapshot",
                      "title": "General",
                      "subject": {
                        "reference": "Patient/5c554347-4290-4b05-83ac-6637ff3bfb40",
                        "type": "Patient"
                      },
                      "encounter": {
                        "reference": "Encounter/6fe12f5b-e35c-4c92-a492-96feda5a1a3b",
                        "type": "Encounter",
                        "display": "unknown"
                      },
                      "entry": [
                        {
                          "item": {
                            "reference": "MedicationStatement/24e860ce-2fdc-4745-aa9e-7d30bb487c4e",
                            "type": "MedicationStatement",
                            "display": "Ibuprofen"
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          ],
          "errors": [],
          "modelVersion": "2022-03-01"
        }
      }
    ]
  }
}

使用客户端库支持运行容器

从容器版本 3.0.017010001-onprem-amd64 开始(或者在使用 latest 容器的情况下),可使用客户端库运行健康状况文本分析容器。 为此,请将以下参数添加到 docker run 命令:

enablelro=true

然后,在对客户端对象进行身份验证时,使用正在运行你的容器的终结点:

http://localhost:5000

例如,如果使用的是 C# ,请使用以下代码:

var client = new TextAnalyticsClient("http://localhost:5000", "your-text-analytics-key");

停止容器

若要关闭容器,请在运行容器的命令行环境中选择 Ctrl+C

故障排除

如果运行启用了输出装入点和日志记录的容器,该容器会生成有助于排查启动或运行容器时发生的问题的日志文件。

提示

如需更多的故障排除信息和指南,请参阅 Azure AI 容器常见问题解答 (FAQ)

计费

健康状况文本分析容器使用 Azure 帐户中的语言资源向 Azure 发送账单信息。

对该容器的查询在用于 ApiKey 参数的 Azure 资源的定价层计费。

Azure 认知服务容器在未连接到计量或计费终结点的情况下无权运行。 必须始终让容器可以向计费终结点传送计费信息。 认知服务容器不会将客户数据(例如,正在分析的图像或文本)发送给 Microsoft。

连接到 Azure

容器需要计费参数值才能运行。 这些值使容器可以连接到计费终结点。 容器约每 10 到 15 分钟报告一次使用情况。 如果容器未在允许的时间范围内连接到 Azure,容器将继续运行,但不会为查询提供服务,直到计费终结点恢复。 尝试连接按 10 到 15 分钟的相同时间间隔进行 10 次。 如果无法在 10 次尝试内连接到计费终结点,容器会停止处理请求。

计费参数

当以下三个选项都提供了有效值时,docker run 命令会启动容器:

选项 说明
ApiKey 用于跟踪计费信息的认知服务资源的 API 密钥。
必须将此选项的值设置为 Billing 中指定的已预配资源的 API 密钥。
Billing 用于跟踪计费信息的认知服务资源的终结点。
必须将此选项的值设置为已预配的 Azure 资源的终结点 URI。
Eula 表示已接受容器的许可条款。
此选项的值必须设置为 accept

总结

在本文中,我们已学习相关的概念,以及健康状况文本分析容器的下载、安装和运行工作流。 综上所述:

  • 健康状况文本分析为 Docker 提供了一个 Linux 容器
  • 从 Microsoft 容器注册表 (MCR) 下载容器映像。
  • 容器映像在 Docker 中运行。
  • 可以使用 REST API 或 SDK 通过指定容器的主机 URI 来调用健康状况文本分析容器中的操作。
  • 必须在实例化容器时指定账单信息。

重要

如果未连接到 Azure 进行计量,则无法授权并运行 Azure AI 容器。 客户需要始终让容器向计量服务传送账单信息。 Azure AI 容器不会向 Microsoft 发送客户数据(例如正在分析的文本)。

后续步骤