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

DocumentModelAdministrationClient class

用于与 表单识别器 服务的模型管理功能交互的客户端,例如创建、读取、列出、删除和复制模型。

示例:

Azure Active Directory

import { DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentModelAdministrationClient(endpoint, credential);

API 密钥 (订阅密钥)

import { DocumentModelAdministrationClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentModelAdministrationClient(endpoint, credential);

构造函数

DocumentModelAdministrationClient(string, KeyCredential, DocumentModelAdministrationClientOptions)

从资源终结点和静态 API 密钥创建 DocumentModelAdministrationClient 实例, () KeyCredential

示例:

import { DocumentModelAdministrationClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentModelAdministrationClient(endpoint, credential);
DocumentModelAdministrationClient(string, TokenCredential, DocumentModelAdministrationClientOptions)

从资源终结点和 Azure 标识 TokenCredential创建 DocumentModelAdministrationClient 实例。

有关使用 Azure Active Directory 进行身份验证的详细信息, @azure/identity 请参阅包。

示例:

import { DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentModelAdministrationClient(endpoint, credential);

方法

beginBuildDocumentClassifier(string, DocumentClassifierDocumentTypeSources, BeginBuildDocumentClassifierOptions)

使用给定的分类器 ID 和文档类型生成新的文档分类器。

分类器 ID 在资源中的分类器中必须是唯一的。

文档类型作为对象提供,该对象将文档类型的名称映射到该文档类型的训练数据集。 支持两种训练数据输入方法:

  • azureBlobSource,它使用给定Azure Blob 存储容器中的数据训练分类器。
  • azureBlobFileListSource,它类似于 azureBlobSource ,但允许使用 JSONL 格式的文件列表对训练数据集中包含的文件进行更精细的控制。

表单识别器服务从 Azure 存储容器读取训练数据集,该数据集作为包含 SAS 令牌的容器的 URL 提供,允许服务后端与容器通信。 至少需要“读取”和“列表”权限。 此外,必须根据特定约定组织给定容器中的数据,该约定记录在 用于生成自定义文档分类器的服务文档中

示例

const classifierId = "aNewClassifier";
const containerUrl1 = "<training data container SAS URL 1>";
const containerUrl2 = "<training data container SAS URL 2>";

const poller = await client.beginBuildDocumentClassifier(
  classifierId,
  {
    // The document types. Each entry in this object should map a document type name to a
    // `ClassifierDocumentTypeDetails` object
    "formX": {
      azureBlobSource: {
        containerUrl: containerUrl1,
      }
    },
    "formY": {
      azureBlobFileListSource: {
        containerUrl: containerUrl2,
        fileList: "path/to/fileList.jsonl"
      }
    },
  },
  {
    // Optionally, a text description may be attached to the classifier
    description: "This is an example classifier!"
  }
);

// Classifier building, like model creation operations, returns a poller that eventually produces a
// DocumentClassifierDetails object
const classifierDetails = await poller.pollUntilDone();

const {
  classifierId, // identical to the classifierId given when creating the classifier
  description, // identical to the description given when creating the classifier (if any)
  createdOn, // the Date (timestamp) that the classifier was created
  docTypes // information about the document types in the classifier and their details
} = classifierDetails;
beginBuildDocumentModel(string, DocumentModelSource, DocumentModelBuildMode, BeginBuildDocumentModelOptions)

从模型内容源生成具有给定 ID 的新模型。

模型 ID 可以包含任何文本,只要它不以“prebuilt-”开头, (因为这些模型指的是所有资源) 通用的预生成表单识别器模型,只要它尚不存在于资源中。

内容源描述了服务用于读取输入训练数据的机制。 有关详细信息, <xref:DocumentModelContentSource> 请参阅 类型。

示例

const modelId = "aNewModel";

const poller = await client.beginBuildDocumentModel(modelId, { containerUrl: "<SAS-encoded blob container URL>" }, {
  // Optionally, a text description may be attached to the model
  description: "This is an example model!"
});

// Model building, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types in the model and their field schemas
} = modelDetails;
beginBuildDocumentModel(string, string, DocumentModelBuildMode, BeginBuildDocumentModelOptions)

从一组输入文档和标记字段生成具有给定 ID 的新模型。

模型 ID 可以包含任何文本,只要它不以“prebuilt-”开头, (因为这些模型指的是所有资源) 通用的预生成表单识别器模型,只要它尚不存在于资源中。

表单识别器服务从 Azure 存储容器读取训练数据集,该数据集作为包含 SAS 令牌的容器的 URL 提供,允许服务后端与容器通信。 至少需要“读取”和“列出”权限。 此外,必须根据特定约定组织给定容器中的数据,该约定记录在 用于生成自定义模型的服务文档中

示例

const modelId = "aNewModel";
const containerUrl = "<training data container SAS URL>";

const poller = await client.beginBuildDocumentModel(modelId, containerUrl, {
  // Optionally, a text description may be attached to the model
  description: "This is an example model!"
});

// Model building, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types in the model and their field schemas
} = modelDetails;
beginComposeDocumentModel(string, Iterable<string>, BeginComposeDocumentModelOptions)

从多个预先存在的子模型创建单个组合模型。

生成的组合模型合并其组件模型的文档类型,并将分类步骤插入提取管道,以确定其哪些组件子模型最适合给定输入。

示例

const modelId = "aNewComposedModel";
const subModelIds = [
  "documentType1Model",
  "documentType2Model",
  "documentType3Model"
];

// The resulting composed model can classify and extract data from documents
// conforming to any of the above document types
const poller = await client.beginComposeDocumentModel(modelId, subModelIds, {
  description: "This is a composed model that can handle several document types."
});

// Model composition, like all other model creation operations, returns a poller that eventually produces a
// ModelDetails object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types of the composed submodels
} = modelDetails;
beginCopyModelTo(string, CopyAuthorization, BeginCopyModelOptions)

将具有给定 ID 的模型复制到由给定复制授权编码的资源和模型 ID 中。

请参阅 CopyAuthorizationgetCopyAuthorization

示例

// We need a client for the source model's resource
const sourceEndpoint = "https://<source resource name>.cognitiveservices.azure.com";
const sourceCredential = new AzureKeyCredential("<source api key>");
const sourceClient = new DocumentModelAdministrationClient(sourceEndpoint, sourceCredential);

// We create the copy authorization using a client authenticated with the destination resource. Note that these two
// resources can be the same (you can copy a model to a new ID in the same resource).
const copyAuthorization = await client.getCopyAuthorization("<destination model ID>");

// Finally, use the _source_ client to copy the model and await the copy operation
const poller = await sourceClient.beginCopyModelTo("<source model ID>");

// Model copying, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the copy authorization
  description, // identical to the description given when creating the copy authorization
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types of the model (identical to the original, source model)
} = modelDetails;
deleteDocumentClassifier(string, OperationOptions)

从客户端的资源中删除具有给定 ID 的分类器(如果存在)。 此操作无法还原。

示例

await client.deleteDocumentClassifier("<classifier ID to delete>"));
deleteDocumentModel(string, DeleteDocumentModelOptions)

从客户端的资源中删除具有给定 ID 的模型(如果存在)。 此操作无法还原。

示例

await client.deleteDocumentModel("<model ID to delete>"));
getCopyAuthorization(string, GetCopyAuthorizationOptions)

创建一个授权,用于将模型复制到资源中,与 方法一起使用 beginCopyModelTo

授予 CopyAuthorization 另一个认知服务资源在此客户端的资源中创建模型的权限,该资源包含编码为授权的模型 ID 和可选说明。

示例

// The copyAuthorization data structure stored below grants any cognitive services resource the right to copy a
// model into the client's resource with the given destination model ID.
const copyAuthorization = await client.getCopyAuthorization("<destination model ID>");
getDocumentClassifier(string, OperationOptions)

检索有关按 ID) (DocumentClassifierDetails 分类器 的信息。

示例

const classifierId = "<classifier ID";

const {
  classifierId, // identical to the ID given when calling `getDocumentClassifier`
  description, // a textual description of the classifier, if provided during classifier creation
  createdOn, // the Date (timestamp) that the classifier was created
  // information about the document types in the classifier and their corresponding traning data
  docTypes
} = await client.getDocumentClassifier(classifierId);

// The `docTypes` property is a map of document type names to information about the training data
// for that document type.
for (const [docTypeName, classifierDocTypeDetails] of Object.entries(docTypes)) {
 console.log(`- '${docTypeName}': `, classifierDocTypeDetails);
}
getDocumentModel(string, GetModelOptions)

(DocumentModelDetails) 按 ID 检索有关模型的信息。

此方法可以检索有关自定义模型和预生成模型的信息。

中断性变更

在以前版本的 表单识别器 REST API 和 SDK 中getModel,该方法可能会返回任何模型,甚至可能返回因错误而无法创建的模型。 在新服务版本中, getDocumentModellistDocumentModels仅生成成功创建的模型 (即“已准备就绪”可供) 使用的模型。 现在,通过“操作”API 检索失败的模型,请参阅 getOperationlistOperations

示例

// The ID of the prebuilt business card model
const modelId = "prebuilt-businessCard";

const {
  modelId, // identical to the modelId given when calling `getDocumentModel`
  description, // a textual description of the model, if provided during model creation
  createdOn, // the Date (timestamp) that the model was created
  // information about the document types in the model and their field schemas
  docTypes: {
    // the document type of the prebuilt business card model
    "prebuilt:businesscard": {
      // an optional, textual description of this document type
      description,
      // the schema of the fields in this document type, see the FieldSchema type
      fieldSchema,
      // the service's confidences in the fields (an object with field names as properties and numeric confidence
      // values)
      fieldConfidence
    }
  }
} = await client.getDocumentModel(modelId);
getOperation(string, GetOperationOptions)

检索有关操作的信息, OperationDetails (按其 ID) 。

操作表示非分析任务,例如生成、撰写或复制模型。

getResourceDetails(GetResourceDetailsOptions)

检索有关此客户端资源的基本信息。

示例

const {
  // Information about the custom models in the current resource
  customDocumentModelDetails: {
    // The number of custom models in the current resource
    count,
    // The maximum number of models that the current resource can support
    limit
  }
} = await client.getResourceDetails();
listDocumentClassifiers(ListModelsOptions)

列出有关资源中的分类器的详细信息。 此操作支持分页。

示例

异步迭代

for await (const details of client.listDocumentClassifiers()) {
  const {
    classifierId, // The classifier's unique ID
    description, // a textual description of the classifier, if provided during creation
    docTypes, // information about the document types in the classifier and their corresponding traning data
  } = details;
}

按页

// The listDocumentClassifiers method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listDocumentClassifiers().byPage();

for await (const page of pages) {
  // Each page is an array of classifiers and can be iterated synchronously
  for (const details of page) {
    const {
      classifierId, // The classifier's unique ID
      description, // a textual description of the classifier, if provided during creation
      docTypes, // information about the document types in the classifier and their corresponding traning data
    } = details;
  }
}
listDocumentModels(ListModelsOptions)

列出资源中模型的摘要。 将包括自定义模型和预生成模型。 此操作支持分页。

DocumentModelSummary) (模型摘要仅包含有关模型的基本信息,不包括有关模型 (中的文档类型的信息,例如字段架构和) 置信度值。

若要访问有关模型的完整信息,请使用 getDocumentModel

中断性变更

在以前版本的 表单识别器 REST API 和 SDK 中listModels, 方法将返回所有模型,甚至返回因错误而无法创建的模型。 在新服务版本中, listDocumentModelsgetDocumentModel仅生成成功创建的模型 (即“已准备就绪”可供) 使用的模型。 现在,通过“操作”API 检索失败的模型,请参阅 getOperationlistOperations

示例

异步迭代

for await (const summary of client.listDocumentModels()) {
  const {
    modelId, // The model's unique ID
    description, // a textual description of the model, if provided during model creation
  } = summary;

  // You can get the full model info using `getDocumentModel`
  const model = await client.getDocumentModel(modelId);
}

按页

// The listDocumentModels method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listDocumentModels().byPage();

for await (const page of pages) {
  // Each page is an array of models and can be iterated synchronously
  for (const model of page) {
    const {
      modelId, // The model's unique ID
      description, // a textual description of the model, if provided during model creation
    } = summary;

    // You can get the full model info using `getDocumentModel`
    const model = await client.getDocumentModel(modelId);
  }
}
listOperations(ListOperationsOptions)

列出资源中的模型创建操作。 这将生成所有操作,包括未能成功创建模型的操作。 此操作支持分页。

示例

异步迭代

for await (const operation of client.listOperations()) {
  const {
    operationId, // the operation's GUID
    status, // the operation status, one of "notStarted", "running", "succeeded", "failed", or "canceled"
    percentCompleted // the progress of the operation, from 0 to 100
  } = operation;
}

按页

// The listOperations method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listOperations().byPage();

for await (const page of pages) {
  // Each page is an array of operation info objects and can be iterated synchronously
  for (const operation of page) {
    const {
      operationId, // the operation's GUID
      status, // the operation status, one of "notStarted", "running", "succeeded", "failed", or "canceled"
      percentCompleted // the progress of the operation, from 0 to 100
    } = operation;
  }
}

构造函数详细信息

DocumentModelAdministrationClient(string, KeyCredential, DocumentModelAdministrationClientOptions)

从资源终结点和静态 API 密钥创建 DocumentModelAdministrationClient 实例, () KeyCredential

示例:

import { DocumentModelAdministrationClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentModelAdministrationClient(endpoint, credential);
new DocumentModelAdministrationClient(endpoint: string, credential: KeyCredential, options?: DocumentModelAdministrationClientOptions)

参数

endpoint

string

Azure 认知服务实例的终结点 URL

credential
KeyCredential

包含认知服务实例订阅密钥的 KeyCredential

options
DocumentModelAdministrationClientOptions

用于在客户端中配置所有方法的可选设置

DocumentModelAdministrationClient(string, TokenCredential, DocumentModelAdministrationClientOptions)

从资源终结点和 Azure 标识 TokenCredential创建 DocumentModelAdministrationClient 实例。

有关使用 Azure Active Directory 进行身份验证的详细信息, @azure/identity 请参阅包。

示例:

import { DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentModelAdministrationClient(endpoint, credential);
new DocumentModelAdministrationClient(endpoint: string, credential: TokenCredential, options?: DocumentModelAdministrationClientOptions)

参数

endpoint

string

Azure 认知服务实例的终结点 URL

credential
TokenCredential

包中的 @azure/identity TokenCredential 实例

options
DocumentModelAdministrationClientOptions

用于在客户端中配置所有方法的可选设置

方法详细信息

beginBuildDocumentClassifier(string, DocumentClassifierDocumentTypeSources, BeginBuildDocumentClassifierOptions)

使用给定的分类器 ID 和文档类型生成新的文档分类器。

分类器 ID 在资源中的分类器中必须是唯一的。

文档类型作为对象提供,该对象将文档类型的名称映射到该文档类型的训练数据集。 支持两种训练数据输入方法:

  • azureBlobSource,它使用给定Azure Blob 存储容器中的数据训练分类器。
  • azureBlobFileListSource,它类似于 azureBlobSource ,但允许使用 JSONL 格式的文件列表对训练数据集中包含的文件进行更精细的控制。

表单识别器服务从 Azure 存储容器读取训练数据集,该数据集作为包含 SAS 令牌的容器的 URL 提供,允许服务后端与容器通信。 至少需要“读取”和“列表”权限。 此外,必须根据特定约定组织给定容器中的数据,该约定记录在 用于生成自定义文档分类器的服务文档中

示例

const classifierId = "aNewClassifier";
const containerUrl1 = "<training data container SAS URL 1>";
const containerUrl2 = "<training data container SAS URL 2>";

const poller = await client.beginBuildDocumentClassifier(
  classifierId,
  {
    // The document types. Each entry in this object should map a document type name to a
    // `ClassifierDocumentTypeDetails` object
    "formX": {
      azureBlobSource: {
        containerUrl: containerUrl1,
      }
    },
    "formY": {
      azureBlobFileListSource: {
        containerUrl: containerUrl2,
        fileList: "path/to/fileList.jsonl"
      }
    },
  },
  {
    // Optionally, a text description may be attached to the classifier
    description: "This is an example classifier!"
  }
);

// Classifier building, like model creation operations, returns a poller that eventually produces a
// DocumentClassifierDetails object
const classifierDetails = await poller.pollUntilDone();

const {
  classifierId, // identical to the classifierId given when creating the classifier
  description, // identical to the description given when creating the classifier (if any)
  createdOn, // the Date (timestamp) that the classifier was created
  docTypes // information about the document types in the classifier and their details
} = classifierDetails;
function beginBuildDocumentClassifier(classifierId: string, docTypeSources: DocumentClassifierDocumentTypeSources, options?: BeginBuildDocumentClassifierOptions): Promise<DocumentClassifierPoller>

参数

classifierId

string

要创建的分类器的唯一 ID

docTypeSources
DocumentClassifierDocumentTypeSources

要包含在分类器中的文档类型及其源 (文档类型名称映射) ClassifierDocumentTypeDetails

options
BeginBuildDocumentClassifierOptions

分类器生成操作的可选设置

返回

长时间运行的操作 (轮询器) ,最终将生成创建的分类器详细信息或错误

beginBuildDocumentModel(string, DocumentModelSource, DocumentModelBuildMode, BeginBuildDocumentModelOptions)

从模型内容源生成具有给定 ID 的新模型。

模型 ID 可以包含任何文本,只要它不以“prebuilt-”开头, (因为这些模型指的是所有资源) 通用的预生成表单识别器模型,只要它尚不存在于资源中。

内容源描述了服务用于读取输入训练数据的机制。 有关详细信息, <xref:DocumentModelContentSource> 请参阅 类型。

示例

const modelId = "aNewModel";

const poller = await client.beginBuildDocumentModel(modelId, { containerUrl: "<SAS-encoded blob container URL>" }, {
  // Optionally, a text description may be attached to the model
  description: "This is an example model!"
});

// Model building, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types in the model and their field schemas
} = modelDetails;
function beginBuildDocumentModel(modelId: string, contentSource: DocumentModelSource, buildMode: DocumentModelBuildMode, options?: BeginBuildDocumentModelOptions): Promise<DocumentModelPoller>

参数

modelId

string

要创建的模型的唯一 ID

contentSource
DocumentModelSource

提供此模型训练数据的内容源

buildMode

DocumentModelBuildMode

生成模型时要使用的模式 (查看 DocumentModelBuildMode)

options
BeginBuildDocumentModelOptions

模型生成操作的可选设置

返回

长时间运行的操作 (轮询器) ,最终将生成创建的模型信息或错误

beginBuildDocumentModel(string, string, DocumentModelBuildMode, BeginBuildDocumentModelOptions)

从一组输入文档和标记字段生成具有给定 ID 的新模型。

模型 ID 可以包含任何文本,只要它不以“prebuilt-”开头, (因为这些模型指的是所有资源) 通用的预生成表单识别器模型,只要它尚不存在于资源中。

表单识别器服务从 Azure 存储容器读取训练数据集,该数据集作为包含 SAS 令牌的容器的 URL 提供,允许服务后端与容器通信。 至少需要“读取”和“列出”权限。 此外,必须根据特定约定组织给定容器中的数据,该约定记录在 用于生成自定义模型的服务文档中

示例

const modelId = "aNewModel";
const containerUrl = "<training data container SAS URL>";

const poller = await client.beginBuildDocumentModel(modelId, containerUrl, {
  // Optionally, a text description may be attached to the model
  description: "This is an example model!"
});

// Model building, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types in the model and their field schemas
} = modelDetails;
function beginBuildDocumentModel(modelId: string, containerUrl: string, buildMode: DocumentModelBuildMode, options?: BeginBuildDocumentModelOptions): Promise<DocumentModelPoller>

参数

modelId

string

要创建的模型的唯一 ID

containerUrl

string

存储训练数据集的 Azure 存储容器的 SAS 编码 URL

buildMode

DocumentModelBuildMode

生成模型时要使用的模式 (请参阅 DocumentModelBuildMode)

options
BeginBuildDocumentModelOptions

模型生成操作的可选设置

返回

长时间运行的操作 (轮询器) ,最终将生成创建的模型信息或错误

beginComposeDocumentModel(string, Iterable<string>, BeginComposeDocumentModelOptions)

从多个预先存在的子模型创建单个组合模型。

生成的组合模型合并其组件模型的文档类型,并将分类步骤插入提取管道,以确定其哪些组件子模型最适合给定输入。

示例

const modelId = "aNewComposedModel";
const subModelIds = [
  "documentType1Model",
  "documentType2Model",
  "documentType3Model"
];

// The resulting composed model can classify and extract data from documents
// conforming to any of the above document types
const poller = await client.beginComposeDocumentModel(modelId, subModelIds, {
  description: "This is a composed model that can handle several document types."
});

// Model composition, like all other model creation operations, returns a poller that eventually produces a
// ModelDetails object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the model
  description, // identical to the description given when creating the model
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types of the composed submodels
} = modelDetails;
function beginComposeDocumentModel(modelId: string, componentModelIds: Iterable<string>, options?: BeginComposeDocumentModelOptions): Promise<DocumentModelPoller>

参数

modelId

string

要创建的模型的唯一 ID

componentModelIds

Iterable<string>

可迭代表示要组合的模型的唯一模型 ID 的字符串

options
BeginComposeDocumentModelOptions

用于创建模型的可选设置

返回

长时间运行的操作 (轮询器) ,最终将生成创建的模型信息或错误

beginCopyModelTo(string, CopyAuthorization, BeginCopyModelOptions)

将具有给定 ID 的模型复制到由给定复制授权编码的资源和模型 ID 中。

请参阅 CopyAuthorizationgetCopyAuthorization

示例

// We need a client for the source model's resource
const sourceEndpoint = "https://<source resource name>.cognitiveservices.azure.com";
const sourceCredential = new AzureKeyCredential("<source api key>");
const sourceClient = new DocumentModelAdministrationClient(sourceEndpoint, sourceCredential);

// We create the copy authorization using a client authenticated with the destination resource. Note that these two
// resources can be the same (you can copy a model to a new ID in the same resource).
const copyAuthorization = await client.getCopyAuthorization("<destination model ID>");

// Finally, use the _source_ client to copy the model and await the copy operation
const poller = await sourceClient.beginCopyModelTo("<source model ID>");

// Model copying, like all other model creation operations, returns a poller that eventually produces a ModelDetails
// object
const modelDetails = await poller.pollUntilDone();

const {
  modelId, // identical to the modelId given when creating the copy authorization
  description, // identical to the description given when creating the copy authorization
  createdOn, // the Date (timestamp) that the model was created
  docTypes // information about the document types of the model (identical to the original, source model)
} = modelDetails;
function beginCopyModelTo(sourceModelId: string, authorization: CopyAuthorization, options?: BeginCopyModelOptions): Promise<DocumentModelPoller>

参数

sourceModelId

string

要复制的源模型的唯一 ID

authorization
CopyAuthorization

复制模型的授权,使用 getCopyAuthorization 创建

options
BeginCopyModelOptions

的可选设置

返回

长时间运行的操作 (轮询器) ,最终将生成复制的模型信息或错误

deleteDocumentClassifier(string, OperationOptions)

从客户端的资源中删除具有给定 ID 的分类器(如果存在)。 此操作无法还原。

示例

await client.deleteDocumentClassifier("<classifier ID to delete>"));
function deleteDocumentClassifier(classifierId: string, options?: OperationOptions): Promise<void>

参数

classifierId

string

要从资源中删除的分类器的唯一 ID

options
OperationOptions

请求的可选设置

返回

Promise<void>

deleteDocumentModel(string, DeleteDocumentModelOptions)

从客户端的资源中删除具有给定 ID 的模型(如果存在)。 此操作无法还原。

示例

await client.deleteDocumentModel("<model ID to delete>"));
function deleteDocumentModel(modelId: string, options?: DeleteDocumentModelOptions): Promise<void>

参数

modelId

string

要从资源中删除的模型的唯一 ID

options
DeleteDocumentModelOptions

请求的可选设置

返回

Promise<void>

getCopyAuthorization(string, GetCopyAuthorizationOptions)

创建一个授权,用于将模型复制到资源中,与 方法一起使用 beginCopyModelTo

授予 CopyAuthorization 另一个认知服务资源在此客户端的资源中创建模型的权限,该资源包含编码为授权的模型 ID 和可选说明。

示例

// The copyAuthorization data structure stored below grants any cognitive services resource the right to copy a
// model into the client's resource with the given destination model ID.
const copyAuthorization = await client.getCopyAuthorization("<destination model ID>");
function getCopyAuthorization(destinationModelId: string, options?: GetCopyAuthorizationOptions): Promise<CopyAuthorization>

参数

destinationModelId

string

目标模型的唯一 ID (用于将模型复制到)

options
GetCopyAuthorizationOptions

用于创建复制授权的可选设置

返回

对给定 modelId 和可选说明进行编码的复制授权

getDocumentClassifier(string, OperationOptions)

检索有关按 ID) (DocumentClassifierDetails 分类器 的信息。

示例

const classifierId = "<classifier ID";

const {
  classifierId, // identical to the ID given when calling `getDocumentClassifier`
  description, // a textual description of the classifier, if provided during classifier creation
  createdOn, // the Date (timestamp) that the classifier was created
  // information about the document types in the classifier and their corresponding traning data
  docTypes
} = await client.getDocumentClassifier(classifierId);

// The `docTypes` property is a map of document type names to information about the training data
// for that document type.
for (const [docTypeName, classifierDocTypeDetails] of Object.entries(docTypes)) {
 console.log(`- '${docTypeName}': `, classifierDocTypeDetails);
}
function getDocumentClassifier(classifierId: string, options?: OperationOptions): Promise<DocumentClassifierDetails>

参数

classifierId

string

要查询的分类器的唯一 ID

options
OperationOptions

请求的可选设置

返回

有关具有给定 ID 的分类器的信息

getDocumentModel(string, GetModelOptions)

(DocumentModelDetails) 按 ID 检索有关模型的信息。

此方法可以检索有关自定义模型和预生成模型的信息。

中断性变更

在以前版本的 表单识别器 REST API 和 SDK 中getModel,该方法可能会返回任何模型,甚至可能返回因错误而无法创建的模型。 在新服务版本中, getDocumentModellistDocumentModels仅生成成功创建的模型 (即“已准备就绪”可供) 使用的模型。 现在,通过“操作”API 检索失败的模型,请参阅 getOperationlistOperations

示例

// The ID of the prebuilt business card model
const modelId = "prebuilt-businessCard";

const {
  modelId, // identical to the modelId given when calling `getDocumentModel`
  description, // a textual description of the model, if provided during model creation
  createdOn, // the Date (timestamp) that the model was created
  // information about the document types in the model and their field schemas
  docTypes: {
    // the document type of the prebuilt business card model
    "prebuilt:businesscard": {
      // an optional, textual description of this document type
      description,
      // the schema of the fields in this document type, see the FieldSchema type
      fieldSchema,
      // the service's confidences in the fields (an object with field names as properties and numeric confidence
      // values)
      fieldConfidence
    }
  }
} = await client.getDocumentModel(modelId);
function getDocumentModel(modelId: string, options?: GetModelOptions): Promise<DocumentModelDetails>

参数

modelId

string

要查询的模型的唯一 ID

options
GetModelOptions

请求的可选设置

返回

有关具有给定 ID 的模型的信息

getOperation(string, GetOperationOptions)

检索有关操作的信息, OperationDetails (按其 ID) 。

操作表示非分析任务,例如生成、撰写或复制模型。

function getOperation(operationId: string, options?: GetOperationOptions): Promise<OperationDetails>

参数

operationId

string

要查询的操作的 ID

options
GetOperationOptions

请求的可选设置

返回

Promise<OperationDetails>

有关具有给定 ID 的操作的信息

示例

// The ID of the operation, which should be a GUID
const operationId = "<operation GUID>";

const {
  operationId, // identical to the operationId given when calling `getOperation`
  kind, // the operation kind, one of "documentModelBuild", "documentModelCompose", or "documentModelCopyTo"
  status, // the status of the operation, one of "notStarted", "running", "failed", "succeeded", or "canceled"
  percentCompleted, // a number between 0 and 100 representing the progress of the operation
  createdOn, // a Date object that reflects the time when the operation was started
  lastUpdatedOn, // a Date object that reflects the time when the operation state was last modified
} = await client.getOperation(operationId);

getResourceDetails(GetResourceDetailsOptions)

检索有关此客户端资源的基本信息。

示例

const {
  // Information about the custom models in the current resource
  customDocumentModelDetails: {
    // The number of custom models in the current resource
    count,
    // The maximum number of models that the current resource can support
    limit
  }
} = await client.getResourceDetails();
function getResourceDetails(options?: GetResourceDetailsOptions): Promise<ResourceDetails>

参数

options
GetResourceDetailsOptions

请求的可选设置

返回

Promise<ResourceDetails>

有关此客户端资源的基本信息

listDocumentClassifiers(ListModelsOptions)

列出有关资源中的分类器的详细信息。 此操作支持分页。

示例

异步迭代

for await (const details of client.listDocumentClassifiers()) {
  const {
    classifierId, // The classifier's unique ID
    description, // a textual description of the classifier, if provided during creation
    docTypes, // information about the document types in the classifier and their corresponding traning data
  } = details;
}

按页

// The listDocumentClassifiers method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listDocumentClassifiers().byPage();

for await (const page of pages) {
  // Each page is an array of classifiers and can be iterated synchronously
  for (const details of page) {
    const {
      classifierId, // The classifier's unique ID
      description, // a textual description of the classifier, if provided during creation
      docTypes, // information about the document types in the classifier and their corresponding traning data
    } = details;
  }
}
function listDocumentClassifiers(options?: ListModelsOptions): PagedAsyncIterableIterator<DocumentClassifierDetails, DocumentClassifierDetails[], PageSettings>

参数

options
ListModelsOptions

分类器请求的可选设置

返回

支持分页的分类器详细信息的异步迭代器

listDocumentModels(ListModelsOptions)

列出资源中模型的摘要。 将包括自定义模型和预生成模型。 此操作支持分页。

DocumentModelSummary) (模型摘要仅包含有关模型的基本信息,不包括有关模型 (中的文档类型的信息,例如字段架构和) 置信度值。

若要访问有关模型的完整信息,请使用 getDocumentModel

中断性变更

在以前版本的 表单识别器 REST API 和 SDK 中listModels, 方法将返回所有模型,甚至返回因错误而无法创建的模型。 在新服务版本中, listDocumentModelsgetDocumentModel仅生成成功创建的模型 (即“已准备就绪”可供) 使用的模型。 现在,通过“操作”API 检索失败的模型,请参阅 getOperationlistOperations

示例

异步迭代

for await (const summary of client.listDocumentModels()) {
  const {
    modelId, // The model's unique ID
    description, // a textual description of the model, if provided during model creation
  } = summary;

  // You can get the full model info using `getDocumentModel`
  const model = await client.getDocumentModel(modelId);
}

按页

// The listDocumentModels method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listDocumentModels().byPage();

for await (const page of pages) {
  // Each page is an array of models and can be iterated synchronously
  for (const model of page) {
    const {
      modelId, // The model's unique ID
      description, // a textual description of the model, if provided during model creation
    } = summary;

    // You can get the full model info using `getDocumentModel`
    const model = await client.getDocumentModel(modelId);
  }
}
function listDocumentModels(options?: ListModelsOptions): PagedAsyncIterableIterator<DocumentModelSummary, DocumentModelSummary[], PageSettings>

参数

options
ListModelsOptions

模型请求的可选设置

返回

支持分页的模型摘要的异步迭代器

listOperations(ListOperationsOptions)

列出资源中的模型创建操作。 这将生成所有操作,包括未能成功创建模型的操作。 此操作支持分页。

示例

异步迭代

for await (const operation of client.listOperations()) {
  const {
    operationId, // the operation's GUID
    status, // the operation status, one of "notStarted", "running", "succeeded", "failed", or "canceled"
    percentCompleted // the progress of the operation, from 0 to 100
  } = operation;
}

按页

// The listOperations method is paged, and you can iterate by page using the `byPage` method.
const pages = client.listOperations().byPage();

for await (const page of pages) {
  // Each page is an array of operation info objects and can be iterated synchronously
  for (const operation of page) {
    const {
      operationId, // the operation's GUID
      status, // the operation status, one of "notStarted", "running", "succeeded", "failed", or "canceled"
      percentCompleted // the progress of the operation, from 0 to 100
    } = operation;
  }
}
function listOperations(options?: ListOperationsOptions): PagedAsyncIterableIterator<OperationSummary, OperationSummary[], PageSettings>

参数

options
ListOperationsOptions

操作请求的可选设置

返回

支持分页的操作信息对象的异步迭代器