Skip to content

Commit

Permalink
[Form Recognizer] Update perf test to use latest FR (#25680)
Browse files Browse the repository at this point in the history
Updates the perf test to use 4.0 version of the library by following the
migration guide from v3 to v4

Fixes #25574
  • Loading branch information
HarshaNalluru authored May 1, 2023
1 parent 95e4019 commit f919b30
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 54 deletions.
73 changes: 36 additions & 37 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/formrecognizer/perf-tests/ai-form-recognizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"@azure/ai-form-recognizer": "^3.2.0",
"@azure/ai-form-recognizer": "^4.0.0",
"@azure/identity": "^2.0.1",
"@azure/test-utils-perf": "^1.0.0",
"@azure/core-util": "^1.3.1",
"dotenv": "^16.0.0",
"tslib": "^2.2.0"
},
Expand All @@ -20,7 +21,6 @@
"eslint": "^8.0.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
"ts-node": "^10.0.0",
"typescript": "~5.0.0"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
import { PerfOptionDictionary, PerfTest, getEnvVar } from "@azure/test-utils-perf";
import {
AzureKeyCredential,
BeginRecognizeCustomFormsOptions,
CustomFormModel,
FormRecognizerClient,
FormTrainingClient,
DocumentModelDetails,
DocumentAnalysisClient,
DocumentModelAdministrationClient,
} from "@azure/ai-form-recognizer";
import { DefaultAzureCredential, TokenCredential } from "@azure/identity";
import { randomUUID } from "@azure/core-util";

function unreachable(message?: string): never {
throw new Error(message ?? "Unreachable Exception.");
}

export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFormsOptions> {
public options: PerfOptionDictionary<BeginRecognizeCustomFormsOptions> = {
interface CustomModelRecognitionTestOptions {
updateIntervalInMs: number;
}

export class CustomModelRecognitionTest extends PerfTest<CustomModelRecognitionTestOptions> {
public options: PerfOptionDictionary<CustomModelRecognitionTestOptions> = {
updateIntervalInMs: {
required: false,
description: "Polling interval in milliseconds",
Expand All @@ -30,10 +34,10 @@ export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFor
* Not thrilled about this, but `globalSetup` only runs once overall, while `setup`
* shouldn't have to train the model every time.
*/
static sessionModel: CustomFormModel | undefined = undefined;
static sessionModel: DocumentModelDetails | undefined = undefined;

private recognizerClient: FormRecognizerClient;
private trainingClient: FormTrainingClient;
private recognizerClient: DocumentAnalysisClient;
private trainingClient: DocumentModelAdministrationClient;

private documentUrl: string;

Expand All @@ -50,8 +54,8 @@ export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFor

const endpoint = getEnvVar("FORM_RECOGNIZER_ENDPOINT");

this.trainingClient = new FormTrainingClient(endpoint, credential);
this.recognizerClient = new FormRecognizerClient(endpoint, credential);
this.trainingClient = new DocumentModelAdministrationClient(endpoint, credential);
this.recognizerClient = new DocumentAnalysisClient(endpoint, credential);

this.documentUrl = getEnvVar("FORM_RECOGNIZER_TEST_DOCUMENT_URL");
}
Expand All @@ -60,12 +64,16 @@ export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFor
const trainingContainerSasUrl = getEnvVar("FORM_RECOGNIZER_TRAINING_CONTAINER_SAS_URL");

try {
const poller = await this.trainingClient.beginTraining(trainingContainerSasUrl, true);
const poller = await this.trainingClient.beginBuildDocumentModel(
randomUUID(),
trainingContainerSasUrl,
"template"
);

CustomModelRecognitionTest.sessionModel = await poller.pollUntilDone();

console.log(`Trained custom model: ${CustomModelRecognitionTest.sessionModel.modelId}`);
} catch (ex: any) {
} catch (ex) {
console.trace(ex);
throw ex;
}
Expand All @@ -75,7 +83,7 @@ export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFor
const modelId = CustomModelRecognitionTest.sessionModel?.modelId;
if (modelId) {
console.log(`Deleting ${modelId}`);
await this.trainingClient.deleteModel(modelId);
await this.trainingClient.deleteDocumentModel(modelId);
}
}

Expand All @@ -85,7 +93,7 @@ export class CustomModelRecognitionTest extends PerfTest<BeginRecognizeCustomFor
return unreachable("Failed to initialize model.");
}

const poller = await this.recognizerClient.beginRecognizeCustomFormsFromUrl(
const poller = await this.recognizerClient.beginAnalyzeDocumentFromUrl(
modelId,
this.documentUrl,
{
Expand Down
Loading

0 comments on commit f919b30

Please sign in to comment.