text: // Copyright (c) Microsoft Corporation.
  // Licensed under the MIT License.
  
  /**
   * Train Form Recognizer custom models
   */
  
  const { FormRecognizerClient, AzureKeyCredential } = require("../../dist");
  
  // Load the .env file if it exists
  require("dotenv").config();
  
  async function main() {
    console.log(`Running TrainModel sample`);
  
    // You will need to set these environment variables or edit the following values
    const endpoint = process.env["COGNITIVE_SERVICE_ENDPOINT"] || "<cognitive services endpoint>";
    const apiKey = process.env["COGNITIVE_SERVICE_API_KEY"] || "<api key>";
  
    const trainingDataSource = process.env["DOCUMENT_SOURCE"] || "<SAS url to the blob container storing training documents>";
  
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const trainingClient = client.getFormTrainingClient();
  
    const poller = await trainingClient.beginTraining(trainingDataSource, false, {
      onProgress: (state) => { console.log(`training status: ${state.status}`); }
    });
    await poller.pollUntilDone();
    const model = poller.getResult();
    console.dir(model, { depth: 4 });
  }
  
  main().catch((err) => {
    console.error("The sample encountered an error:", err);
  });
  