通过


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

目录 API 参考

重要

  • Foundry Local 以预览版形式提供。 通过公共预览版,可以提前访问正处于开发状态的功能。
  • 正式发布 (GA) 之前,功能、方法和流程可能会发生更改或功能受限。

Foundry Local 允许生成和集成自己的目录服务。 本文介绍:

  • 目录 API 所需的模型格式
  • 目录 API 与 Foundry Local 集成所需的请求和响应格式

先决条件

  • 已安装 Foundry Local。
  • 可以运行公开终结点的 POST Web 服务。
  • 模型项目以 ONNX 格式提供。
  • Azure 基于角色的访问控制 (RBAC):不适用。

模型格式

若要使用 Foundry Local,模型目录必须包含 开放神经网络交换(ONNX) 格式的模型文件。 若要了解如何将拥抱人脸和 PyTorch 模型编译到 ONNX,请参阅 编译拥抱人脸模型以在本地 Foundry 上运行

API 格式

请求

在接受 JSON 请求正文的目录服务中实现 POST 终结点。 目录 API 的请求格式如下所示:

  • 方法POST
  • Content-Typeapplication/json

示例请求

curl -X POST <your-catalog-api-endpoint> \
-H "Content-Type: application/json" \
-d '{
  "resourceIds": [
    {
      "resourceId": "azureml",
      "entityContainerType": "Registry"
    }
  ],
  "indexEntitiesRequest": {
    "filters": [
      {
        "field": "type",
        "operator": "eq",
        "values": [
          "models"
        ]
      },
      {
        "field": "kind",
        "operator": "eq",
        "values": [
          "Versioned"
        ]
      },
      {
        "field": "properties/variantInfo/variantMetadata/device",
        "operator": "eq",
        "values": [
          "cpu",
          "gpu"
        ]
      },
      {
        "field": "properties/variantInfo/variantMetadata/executionProvider",
        "operator": "eq",
        "values": [
          "cpuexecutionprovider",
          "webgpuexecutionprovider"
        ]
      }
    ],
    "pageSize": 10,
    "skip": null,
    "continuationToken": null
  }
}'

替换为 <your-catalog-api-endpoint> 目录服务 URL。

预期发生的情况

  • 成功的响应包括一个 indexEntitiesResponse 对象。
  • 搜索结果在 . 中 indexEntitiesResponse.value返回。

参考:

请求正文必须是具有以下字段的 JSON 对象:

  • resourceIds:指定要查询的资源的资源 ID 的数组。 每个项包括:
    • resourceId:资源的 ID。
    • entityContainerType:实体容器的类型,例如 RegistryWorkspace和其他。
  • indexEntitiesRequest:包含搜索参数的对象。
    • filters:一组筛选器对象,用于指定筛选搜索结果的条件。 每个筛选器包括:
      • field:要筛选的字段,例如typekind,和其他字段。
      • operator:要用于筛选器的运算符。 例如, eq (等于)、 ne (不等于)、 gt (大于)、 lt (小于)和其他。
      • values:要与字段匹配的值数组。
    • orderBy:要按其对结果进行排序的字段数组。
    • searchText:在结果中搜索的字符串。
    • pageSize:要返回的最大结果数(对于分页)。
    • skip:要跳过的结果数(对于分页)。
    • continuationToken:一个令牌,用于分页以从上一个请求继续。

可筛选字段(可选)

实现目录 API,使其接受 请求 格式。 服务器端筛选是可选的。 跳过服务器端筛选可以更快地实现,但搜索模型效率较低。

如果实现服务器端筛选,请使用以下字段:

  • type:模型的类型,例如modelsdatasets,等等。
  • kind:模型的类型,例如VersionedUnversioned,和其他模型。
  • properties/variantInfo/variantMetadata/device:设备类型,例如 cpugpu和其他类型。
  • properties/variantInfo/variantMetadata/executionProvider:执行提供程序,例如cpuexecutionproviderwebgpuexecutionprovider,和其他。

响应

目录 API 返回包含搜索结果的 JSON 对象。

示例响应

{
  "indexEntitiesResponse": {
    "totalCount": 1,
    "value": [
      {
        "assetId": "example-asset-id",
        "version": "1",
        "properties": {
          "name": "example-model",
          "version": 1,
          "variantInfo": {
            "variantMetadata": {
              "device": "cpu",
              "executionProvider": "cpuexecutionprovider"
            }
          }
        }
      }
    ],
    "nextSkip": null,
    "continuationToken": null
  }
}

响应架构

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "indexEntitiesResponse": {
      "type": "object",
      "properties": {
        "totalCount": {
          "type": "integer",
          "description": "The total count of entities."
        },
        "value": {
          "type": "array",
          "description": "An array of LocalModel objects.",
          "items": {
            "$ref": "#/definitions/LocalModel"
          }
        },
        "nextSkip": {
          "type": "integer",
          "description": "The number of items to skip for the next request."
        },
        "continuationToken": {
          "type": "string",
          "description": "A token to continue fetching results."
        }
      }
    }
  },
  "definitions": {
    "LocalModel": {
      "type": "object",
      "properties": {
        "annotations": {
          "type": "object",
          "description": "Annotations associated with the model.",
          "properties": {
            "tags": {
              "type": "object",
              "description": "Tags associated with the annotation.",
              "properties": {
                "author": { "type": "string" },
                "alias": { "type": "string" },
                "directoryPath": { "type": "string" },
                "license": { "type": "string" },
                "licenseDescription": { "type": "string" },
                "promptTemplate": { "type": "string" },
                "task": { "type": "string" }
              }
            },
            "systemCatalogData": {
              "type": "object",
              "properties": {
                "publisher": { "type": "string" },
                "displayName": { "type": "string" }
              }
            },
            "name": { "type": "string" }
          }
        },
        "properties": {
          "type": "object",
          "description": "Properties of the model.",
          "properties": {
            "name": { "type": "string" },
            "version": { "type": "integer" },
            "alphanumericVersion": { "type": "string" },
            "variantInfo": {
              "type": "object",
              "properties": {
                "parents": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "assetId": { "type": "string" }
                    }
                  }
                },
                "variantMetadata": {
                  "type": "object",
                  "properties": {
                    "modelType": { "type": "string" },
                    "device": { "type": "string" },
                    "executionProvider": { "type": "string" },
                    "fileSizeBytes": { "type": "integer" }
                  }
                }
              }
            }
          }
        },
        "version": {
          "type": "string",
          "description": "The version of the model."
        },
        "assetId": {
          "type": "string",
          "description": "The asset ID of the model."
        }
      }
    }
  }
}

参考: