你当前正在访问 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 密钥(KeyCredential)创建 DocumentModelAdministrationClient 实例

例:

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 存储容器中读取训练数据集,该数据集以 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 可以包含任何文本,只要它不以“预生成”开头(因为这些模型是指所有资源通用的预生成表单识别器模型),并且只要它不存在于资源中。

内容源描述服务用于读取输入训练数据的机制。 有关详细信息,请参阅 <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 可以包含任何文本,只要它不以“预生成”开头(因为这些模型是指所有资源通用的预生成表单识别器模型),并且只要它不存在于资源中。

表单识别器服务从 Azure 存储容器中读取训练数据集,该数据集以 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)

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

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

中断性变更

在早期版本的表单识别器 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)

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

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

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 密钥(KeyCredential)创建 DocumentModelAdministrationClient 实例

例:

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 存储容器中读取训练数据集,该数据集以 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 可以包含任何文本,只要它不以“预生成”开头(因为这些模型是指所有资源通用的预生成表单识别器模型),并且只要它不存在于资源中。

内容源描述服务用于读取输入训练数据的机制。 有关详细信息,请参阅 <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 可以包含任何文本,只要它不以“预生成”开头(因为这些模型是指所有资源通用的预生成表单识别器模型),并且只要它不存在于资源中。

表单识别器服务从 Azure 存储容器中读取训练数据集,该数据集以 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(要将模型复制到的 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)

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

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

中断性变更

在早期版本的表单识别器 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)

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

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

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

作请求的可选设置

返回

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