Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FormTrainingClient

Package version

Client class for training and managing custom form models.

Hierarchy

  • FormTrainingClient

Index

Constructors

constructor

Properties

endpointUrl

endpointUrl: string

Url to an Azure Form Recognizer service endpoint

Methods

beginCopyModel

  • Copies a custom model from this resource (the source) to the specified target Form Recognizer resource. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const targetClient = new FormTrainingClient(targetEndpoint, new AzureKeyCredential(targetApiKey));
    const authorization = await targetClient.getCopyAuthorization(targetResourceId, targetResourceRegion);
    
    const sourceClient = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await sourceClient.beginCopyModel(sourceModelId, authorization, {
      onProgress: (state) => {
        console.log(`Copy model status: ${state.status}`);
      }
    });
    const result = await poller.pollUntilDone();
    summary

    Copies custom model to target resource

    Parameters

    • modelId: string

      Id of the custom model in this resource to be copied to the target Form Recognizer resource

    • target: CopyAuthorization

      Copy authorization produced by calling targetTrainingClient.getCopyAuthorization()

    • Default value options: BeginCopyModelOptions = {}

    Returns Promise<PollerLike<CopyModelOperationState, CustomFormModelInfo>>

beginTraining

  • Creates and trains a custom form model. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Note that when training operation fails, a model is still created in Azure Form Recognizer resource.

    Example usage:

    const trainingFilesUrl = "<url to the blob container storing training documents>";
    const trainingClient = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    
    const poller = await trainingClient.beginTraining(trainingFilesUrl, false, {
      onProgress: (state) => { console.log("training status: "); console.log(state); }
    });
    const model = await poller.pollUntilDone();
    summary

    Creates and trains a model

    Parameters

    • trainingFilesUrl: string

      Accessible url to an Azure Storage Blob container storing the training documents

    • useTrainingLabels: boolean

      specifies whether to training the model using label files

    • Default value options: BeginTrainingOptions = {}

    Returns Promise<PollerLike<TrainingOperationState, CustomFormModel>>

deleteModel

getAccountProperties

getCopyAuthorization

  • Generate an authorization for copying a custom model into this Azure Form Recognizer resource.

    This method should be called on a client that is authenticated using the target resource (where the model will be copied to) credentials, and the output can be passed as the target parameter to the beginCopyModel method of a source client.

    The required resourceId and resourceRegion are properties of an Azure Form Recognizer resource and their values can be found in the Azure Portal.

    Parameters

    • resourceId: string

      Id of the Azure Form Recognizer resource where a custom model will be copied to

    • resourceRegion: string

      Location of the Azure Form Recognizer resource, must be a valid region name supported by Azure Cognitive Services. See https://aka.ms/azsdk/cognitiveservices/regionalavailability for information about the regional availability of Azure Cognitive Services.

    • Default value options: GetCopyAuthorizationOptions = {}

    Returns Promise<CopyAuthorization>

    The authorization to copy a custom model

getCustomModel

getFormRecognizerClient

listCustomModels

  • Returns an async iterable iterator to list information about all models in the cognitive service account.

    .byPage() returns an async iterable iterator to list the blobs in pages.

    Example using for await syntax:

    const client = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey));
    const result = client.listCustomModels();
    let i = 1;
    for await (const model of result) {
      console.log(`model ${i++}:`);
      console.log(model);
    }

    Example using iter.next():

    let i = 1;
    let iter = client.listCustomModels();
    let modelItem = await iter.next();
    while (!modelItem.done) {
      console.log(`model ${i++}: ${modelItem.value}`);
      modelItem = await iter.next();
    }

    Example using byPage():

     let i = 1;
     for await (const response of client.listCustomModels().byPage()) {
       for (const modelInfo of response.modelList!) {
         console.log(`model ${i++}: ${modelInfo.modelId}`);
       }
     }

    Parameters

    Returns PagedAsyncIterableIterator<CustomFormModelInfo, ListCustomModelsResponse>

Generated using TypeDoc