Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form Recognizer] Update perf test to use latest FR #25680

Merged
merged 9 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions common/config/rush/pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
"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",
"dotenv": "^16.0.0",
"uuid": "^9.0.0",
"tslib": "^2.2.0"
},
"devDependencies": {
"@types/node": "^14.0.0",
"@types/uuid": "^9.0.1",
"eslint": "^8.0.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
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 { v4 as generateUuid } from "uuid";

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 +35,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 +55,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,7 +65,7 @@ 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(generateUuid(), trainingContainerSasUrl, "template");

CustomModelRecognitionTest.sessionModel = await poller.pollUntilDone();

Expand All @@ -75,7 +80,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 +90,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
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "../../../../tsconfig.package",
"compilerOptions": {
"module": "commonjs",
"declarationDir": "./types/latest",
"outDir": "./dist-esm"
},
"compileOnSave": true,
"exclude": ["node_modules"],
"include": ["./test/**/*.ts"]
}