@azure/ai-form-recognizer 5.0.0-alpha.20250227.1 → 5.0.0-alpha.20250228.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +292 -330
- package/dist/browser/documentAnalysisClient.d.ts +220 -131
- package/dist/browser/documentAnalysisClient.d.ts.map +1 -1
- package/dist/browser/documentAnalysisClient.js +57 -35
- package/dist/browser/documentAnalysisClient.js.map +1 -1
- package/dist/browser/documentModelAdministrationClient.d.ts +291 -123
- package/dist/browser/documentModelAdministrationClient.d.ts.map +1 -1
- package/dist/browser/documentModelAdministrationClient.js +184 -82
- package/dist/browser/documentModelAdministrationClient.js.map +1 -1
- package/dist/browser/lro/util/delayMs.d.ts +1 -1
- package/dist/browser/lro/util/delayMs.js +1 -1
- package/dist/browser/lro/util/delayMs.js.map +1 -1
- package/dist/commonjs/documentAnalysisClient.d.ts +220 -131
- package/dist/commonjs/documentAnalysisClient.d.ts.map +1 -1
- package/dist/commonjs/documentAnalysisClient.js +57 -35
- package/dist/commonjs/documentAnalysisClient.js.map +1 -1
- package/dist/commonjs/documentModelAdministrationClient.d.ts +291 -123
- package/dist/commonjs/documentModelAdministrationClient.d.ts.map +1 -1
- package/dist/commonjs/documentModelAdministrationClient.js +184 -82
- package/dist/commonjs/documentModelAdministrationClient.js.map +1 -1
- package/dist/commonjs/lro/util/delayMs.d.ts +1 -1
- package/dist/commonjs/lro/util/delayMs.js +1 -1
- package/dist/commonjs/lro/util/delayMs.js.map +1 -1
- package/dist/esm/documentAnalysisClient.d.ts +220 -131
- package/dist/esm/documentAnalysisClient.d.ts.map +1 -1
- package/dist/esm/documentAnalysisClient.js +57 -35
- package/dist/esm/documentAnalysisClient.js.map +1 -1
- package/dist/esm/documentModelAdministrationClient.d.ts +291 -123
- package/dist/esm/documentModelAdministrationClient.d.ts.map +1 -1
- package/dist/esm/documentModelAdministrationClient.js +184 -82
- package/dist/esm/documentModelAdministrationClient.js.map +1 -1
- package/dist/esm/lro/util/delayMs.d.ts +1 -1
- package/dist/esm/lro/util/delayMs.js +1 -1
- package/dist/esm/lro/util/delayMs.js.map +1 -1
- package/dist/react-native/documentAnalysisClient.d.ts +220 -131
- package/dist/react-native/documentAnalysisClient.d.ts.map +1 -1
- package/dist/react-native/documentAnalysisClient.js +57 -35
- package/dist/react-native/documentAnalysisClient.js.map +1 -1
- package/dist/react-native/documentModelAdministrationClient.d.ts +291 -123
- package/dist/react-native/documentModelAdministrationClient.d.ts.map +1 -1
- package/dist/react-native/documentModelAdministrationClient.js +184 -82
- package/dist/react-native/documentModelAdministrationClient.js.map +1 -1
- package/dist/react-native/lro/util/delayMs.d.ts +1 -1
- package/dist/react-native/lro/util/delayMs.js +1 -1
- package/dist/react-native/lro/util/delayMs.js.map +1 -1
- package/package.json +19 -18
|
@@ -13,25 +13,27 @@ import type { ClassifyDocumentOptions } from "./options/ClassifyDocumentOptions.
|
|
|
13
13
|
*
|
|
14
14
|
* #### Azure Active Directory
|
|
15
15
|
*
|
|
16
|
-
* ```
|
|
17
|
-
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
16
|
+
* ```ts snippet:ReadmeSampleCreateClient_TokenCredential
|
|
18
17
|
* import { DefaultAzureCredential } from "@azure/identity";
|
|
18
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
19
19
|
*
|
|
20
|
-
* const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
|
21
20
|
* const credential = new DefaultAzureCredential();
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* const client = new DocumentAnalysisClient(
|
|
22
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
23
|
+
* credential,
|
|
24
|
+
* );
|
|
24
25
|
* ```
|
|
25
26
|
*
|
|
26
27
|
* #### API Key (Subscription Key)
|
|
27
28
|
*
|
|
28
|
-
* ```
|
|
29
|
-
* import {
|
|
30
|
-
*
|
|
31
|
-
* const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
|
32
|
-
* const credential = new AzureKeyCredential("<api key>");
|
|
29
|
+
* ```ts snippet:ReadmeSampleCreateClient_KeyCredential
|
|
30
|
+
* import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
33
31
|
*
|
|
34
|
-
* const
|
|
32
|
+
* const credential = new AzureKeyCredential("<API key>");
|
|
33
|
+
* const client = new DocumentAnalysisClient(
|
|
34
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
35
|
+
* credential,
|
|
36
|
+
* );
|
|
35
37
|
* ```
|
|
36
38
|
*/
|
|
37
39
|
export declare class DocumentAnalysisClient {
|
|
@@ -45,14 +47,15 @@ export declare class DocumentAnalysisClient {
|
|
|
45
47
|
*
|
|
46
48
|
* ### Example:
|
|
47
49
|
*
|
|
48
|
-
* ```
|
|
49
|
-
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
50
|
+
* ```ts snippet:ReadmeSampleCreateClient_TokenCredential
|
|
50
51
|
* import { DefaultAzureCredential } from "@azure/identity";
|
|
52
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
51
53
|
*
|
|
52
|
-
* const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
|
53
54
|
* const credential = new DefaultAzureCredential();
|
|
54
|
-
*
|
|
55
|
-
*
|
|
55
|
+
* const client = new DocumentAnalysisClient(
|
|
56
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
57
|
+
* credential,
|
|
58
|
+
* );
|
|
56
59
|
* ```
|
|
57
60
|
*
|
|
58
61
|
* @param endpoint - the endpoint URL of an Azure Cognitive Services instance
|
|
@@ -65,13 +68,14 @@ export declare class DocumentAnalysisClient {
|
|
|
65
68
|
*
|
|
66
69
|
* ### Example:
|
|
67
70
|
*
|
|
68
|
-
* ```
|
|
69
|
-
* import {
|
|
70
|
-
*
|
|
71
|
-
* const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
|
72
|
-
* const credential = new AzureKeyCredential("<api key>");
|
|
71
|
+
* ```ts snippet:ReadmeSampleCreateClient_KeyCredential
|
|
72
|
+
* import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
73
73
|
*
|
|
74
|
-
* const
|
|
74
|
+
* const credential = new AzureKeyCredential("<API key>");
|
|
75
|
+
* const client = new DocumentAnalysisClient(
|
|
76
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
77
|
+
* credential,
|
|
78
|
+
* );
|
|
75
79
|
* ```
|
|
76
80
|
*
|
|
77
81
|
* @param endpoint - the endpoint URL of an Azure Cognitive Services instance
|
|
@@ -99,32 +103,52 @@ export declare class DocumentAnalysisClient {
|
|
|
99
103
|
* This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
|
|
100
104
|
* objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
|
|
101
105
|
*
|
|
102
|
-
* ```
|
|
103
|
-
* import
|
|
106
|
+
* ```ts snippet:ReadmeSamplePrebuiltReceipt
|
|
107
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
108
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
109
|
+
* import { createReadStream } from "node:fs";
|
|
110
|
+
* import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
|
|
111
|
+
*
|
|
112
|
+
* const credential = new DefaultAzureCredential();
|
|
113
|
+
* const client = new DocumentAnalysisClient(
|
|
114
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
115
|
+
* credential,
|
|
116
|
+
* );
|
|
104
117
|
*
|
|
105
|
-
* const
|
|
118
|
+
* const path = "<path to a document>";
|
|
119
|
+
* const readStream = createReadStream(path);
|
|
106
120
|
*
|
|
107
|
-
* // The
|
|
108
|
-
*
|
|
109
|
-
*
|
|
121
|
+
* // The PrebuiltReceiptModel `DocumentModel` instance encodes both the model ID and a stronger return type for the operation
|
|
122
|
+
* const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, readStream, {
|
|
123
|
+
* onProgress: ({ status }) => {
|
|
124
|
+
* console.log(`status: ${status}`);
|
|
125
|
+
* },
|
|
126
|
+
* });
|
|
110
127
|
*
|
|
111
|
-
* // The result is a long-running operation (poller), which must itself be polled until the operation completes
|
|
112
128
|
* const {
|
|
113
|
-
*
|
|
114
|
-
* tables, // extracted tables, organized into cells that contain their contents
|
|
115
|
-
* styles, // text styles (ex. handwriting) that were observed in the document
|
|
116
|
-
* keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
|
|
117
|
-
* entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
|
|
118
|
-
* documents // extracted documents (instances of one of the model's document types and its field schema)
|
|
129
|
+
* documents: [receiptDocument],
|
|
119
130
|
* } = await poller.pollUntilDone();
|
|
120
131
|
*
|
|
121
|
-
* //
|
|
122
|
-
* const
|
|
132
|
+
* // The fields of the document constitute the extracted receipt data.
|
|
133
|
+
* const receipt = receiptDocument.fields;
|
|
134
|
+
*
|
|
135
|
+
* if (receipt === undefined) {
|
|
136
|
+
* throw new Error("Expected at least one receipt in analysis result.");
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* console.log(`Receipt data (${receiptDocument.docType})`);
|
|
140
|
+
* console.log(" Merchant Name:", receipt.merchantName?.value);
|
|
123
141
|
*
|
|
124
|
-
* // The
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
142
|
+
* // The items of the receipt are an example of a `DocumentArrayValue`
|
|
143
|
+
* if (receipt.items !== undefined) {
|
|
144
|
+
* console.log("Items:");
|
|
145
|
+
* for (const { properties: item } of receipt.items.values) {
|
|
146
|
+
* console.log("- Description:", item.description?.value);
|
|
147
|
+
* console.log(" Total Price:", item.totalPrice?.value);
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
*
|
|
151
|
+
* console.log(" Total:", receipt.total?.value);
|
|
128
152
|
* ```
|
|
129
153
|
*
|
|
130
154
|
*
|
|
@@ -149,35 +173,52 @@ export declare class DocumentAnalysisClient {
|
|
|
149
173
|
* {@link beginAnalyzeDocumentFromUrl} method for more information. Use of that method is preferred when using URLs,
|
|
150
174
|
* and URL support is only provided in this method for backwards compatibility.
|
|
151
175
|
*
|
|
152
|
-
* ```
|
|
153
|
-
* import
|
|
176
|
+
* ```ts snippet:ReadmeSamplePrebuiltReceipt
|
|
177
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
178
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
179
|
+
* import { createReadStream } from "node:fs";
|
|
180
|
+
* import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
|
|
154
181
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
182
|
+
* const credential = new DefaultAzureCredential();
|
|
183
|
+
* const client = new DocumentAnalysisClient(
|
|
184
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
185
|
+
* credential,
|
|
186
|
+
* );
|
|
158
187
|
*
|
|
159
|
-
* const
|
|
188
|
+
* const path = "<path to a document>";
|
|
189
|
+
* const readStream = createReadStream(path);
|
|
160
190
|
*
|
|
161
|
-
* // The
|
|
162
|
-
*
|
|
163
|
-
*
|
|
191
|
+
* // The PrebuiltReceiptModel `DocumentModel` instance encodes both the model ID and a stronger return type for the operation
|
|
192
|
+
* const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, readStream, {
|
|
193
|
+
* onProgress: ({ status }) => {
|
|
194
|
+
* console.log(`status: ${status}`);
|
|
195
|
+
* },
|
|
196
|
+
* });
|
|
164
197
|
*
|
|
165
|
-
* // The result is a long-running operation (poller), which must itself be polled until the operation completes
|
|
166
198
|
* const {
|
|
167
|
-
*
|
|
168
|
-
* tables, // extracted tables, organized into cells that contain their contents
|
|
169
|
-
* styles, // text styles (ex. handwriting) that were observed in the document
|
|
170
|
-
* keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
|
|
171
|
-
*
|
|
172
|
-
* documents // extracted documents (instances of one of the model's document types and its field schema)
|
|
199
|
+
* documents: [receiptDocument],
|
|
173
200
|
* } = await poller.pollUntilDone();
|
|
174
201
|
*
|
|
175
|
-
* //
|
|
176
|
-
* const
|
|
202
|
+
* // The fields of the document constitute the extracted receipt data.
|
|
203
|
+
* const receipt = receiptDocument.fields;
|
|
204
|
+
*
|
|
205
|
+
* if (receipt === undefined) {
|
|
206
|
+
* throw new Error("Expected at least one receipt in analysis result.");
|
|
207
|
+
* }
|
|
177
208
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
209
|
+
* console.log(`Receipt data (${receiptDocument.docType})`);
|
|
210
|
+
* console.log(" Merchant Name:", receipt.merchantName?.value);
|
|
211
|
+
*
|
|
212
|
+
* // The items of the receipt are an example of a `DocumentArrayValue`
|
|
213
|
+
* if (receipt.items !== undefined) {
|
|
214
|
+
* console.log("Items:");
|
|
215
|
+
* for (const { properties: item } of receipt.items.values) {
|
|
216
|
+
* console.log("- Description:", item.description?.value);
|
|
217
|
+
* console.log(" Total Price:", item.totalPrice?.value);
|
|
218
|
+
* }
|
|
219
|
+
* }
|
|
220
|
+
*
|
|
221
|
+
* console.log(" Total:", receipt.total?.value);
|
|
181
222
|
* ```
|
|
182
223
|
*
|
|
183
224
|
* @param model - a {@link DocumentModel} representing the model to use for analysis and the expected output type
|
|
@@ -205,31 +246,46 @@ export declare class DocumentAnalysisClient {
|
|
|
205
246
|
* token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
|
|
206
247
|
* request the file.
|
|
207
248
|
*
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* // The result is a long-running operation (poller), which must itself be polled until the operation completes
|
|
217
|
-
* const {
|
|
218
|
-
* pages, // pages extracted from the document, which contain lines and words
|
|
219
|
-
* tables, // extracted tables, organized into cells that contain their contents
|
|
220
|
-
* styles, // text styles (ex. handwriting) that were observed in the document
|
|
221
|
-
* keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
|
|
222
|
-
*
|
|
223
|
-
* documents // extracted documents (instances of one of the model's document types and its field schema)
|
|
224
|
-
* } = await poller.pollUntilDone();
|
|
225
|
-
*
|
|
226
|
-
* // Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
|
|
227
|
-
* const [{ fields: receipt }] = documents;
|
|
249
|
+
* ```ts snippet:ReadmeSampleReceiptModelID_URL
|
|
250
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
251
|
+
* import {
|
|
252
|
+
* DocumentAnalysisClient,
|
|
253
|
+
* DocumentStringField,
|
|
254
|
+
* DocumentArrayField,
|
|
255
|
+
* DocumentObjectField,
|
|
256
|
+
* } from "@azure/ai-form-recognizer";
|
|
228
257
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
258
|
+
* const credential = new DefaultAzureCredential();
|
|
259
|
+
* const client = new DocumentAnalysisClient(
|
|
260
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
261
|
+
* credential,
|
|
262
|
+
* );
|
|
263
|
+
*
|
|
264
|
+
* const poller = await client.beginAnalyzeDocumentFromUrl(
|
|
265
|
+
* "prebuilt-receipt",
|
|
266
|
+
* // The Document Intelligence service will access the following URL to a receipt image and extract data from it
|
|
267
|
+
* "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png",
|
|
268
|
+
* );
|
|
269
|
+
* poller.onProgress((state) => console.log("Operation:", state.modelId, state.status));
|
|
270
|
+
*
|
|
271
|
+
* const { documents } = await poller.pollUntilDone();
|
|
272
|
+
*
|
|
273
|
+
* const result = documents && documents[0];
|
|
274
|
+
* if (result) {
|
|
275
|
+
* const receipt = result.fields;
|
|
276
|
+
* console.log("=== Receipt Information ===");
|
|
277
|
+
* console.log("Type:", result.docType);
|
|
278
|
+
* console.log("Merchant:", (receipt["MerchantName"] as DocumentStringField).value);
|
|
279
|
+
*
|
|
280
|
+
* console.log("Items:");
|
|
281
|
+
* for (const { properties: item } of ((receipt["Items"] as DocumentArrayField).values ||
|
|
282
|
+
* []) as DocumentObjectField[]) {
|
|
283
|
+
* console.log("- Description:", (item["Description"] as DocumentStringField).value);
|
|
284
|
+
* console.log(" Total Price:", (item["TotalPrice"] as DocumentStringField).value);
|
|
285
|
+
* }
|
|
286
|
+
* } else {
|
|
287
|
+
* throw new Error("Expected at least one receipt in the result.");
|
|
288
|
+
* }
|
|
233
289
|
* ```
|
|
234
290
|
*
|
|
235
291
|
* @param modelId - the unique ID (name) of the model within this client's resource
|
|
@@ -251,34 +307,47 @@ export declare class DocumentAnalysisClient {
|
|
|
251
307
|
* token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
|
|
252
308
|
* request the file.
|
|
253
309
|
*
|
|
254
|
-
* ```
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* import { PrebuiltReceiptModel } from "
|
|
310
|
+
* ```ts snippet:ReadmeSampleReceiptPrebuilt_URL
|
|
311
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
312
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
313
|
+
* import { PrebuiltReceiptModel } from "../samples-dev/prebuilt/prebuilt-receipt.js";
|
|
258
314
|
*
|
|
259
|
-
*
|
|
260
|
-
* const
|
|
315
|
+
* const credential = new DefaultAzureCredential();
|
|
316
|
+
* const client = new DocumentAnalysisClient(
|
|
317
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
318
|
+
* credential,
|
|
319
|
+
* );
|
|
261
320
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
321
|
+
* const poller = await client.beginAnalyzeDocumentFromUrl(
|
|
322
|
+
* PrebuiltReceiptModel,
|
|
323
|
+
* // The Document Intelligence service will access the following URL to a receipt image and extract data from it
|
|
324
|
+
* "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png",
|
|
325
|
+
* );
|
|
265
326
|
*
|
|
266
|
-
* // The result is a long-running operation (poller), which must itself be polled until the operation completes
|
|
267
327
|
* const {
|
|
268
|
-
*
|
|
269
|
-
* tables, // extracted tables, organized into cells that contain their contents
|
|
270
|
-
* styles, // text styles (ex. handwriting) that were observed in the document
|
|
271
|
-
* keyValuePairs, // extracted pairs of elements (directed associations from one element in the input to another)
|
|
272
|
-
*
|
|
273
|
-
* documents // extracted documents (instances of one of the model's document types and its field schema)
|
|
328
|
+
* documents: [document],
|
|
274
329
|
* } = await poller.pollUntilDone();
|
|
275
330
|
*
|
|
276
|
-
* //
|
|
277
|
-
*
|
|
331
|
+
* // Use of PrebuiltModels.Receipt above (rather than the raw model ID), as it adds strong typing of the model's output
|
|
332
|
+
* if (document) {
|
|
333
|
+
* const { merchantName, items, total } = document.fields;
|
|
334
|
+
*
|
|
335
|
+
* console.log("=== Receipt Information ===");
|
|
336
|
+
* console.log("Type:", document.docType);
|
|
337
|
+
* console.log("Merchant:", merchantName && merchantName.value);
|
|
338
|
+
*
|
|
339
|
+
* console.log("Items:");
|
|
340
|
+
* for (const item of (items && items.values) || []) {
|
|
341
|
+
* const { description, totalPrice } = item.properties;
|
|
342
|
+
*
|
|
343
|
+
* console.log("- Description:", description && description.value);
|
|
344
|
+
* console.log(" Total Price:", totalPrice && totalPrice.value);
|
|
345
|
+
* }
|
|
278
346
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
347
|
+
* console.log("Total:", total && total.value);
|
|
348
|
+
* } else {
|
|
349
|
+
* throw new Error("Expected at least one receipt in the result.");
|
|
350
|
+
* }
|
|
282
351
|
* ```
|
|
283
352
|
*
|
|
284
353
|
* @param model - a {@link DocumentModel} representing the model to use for analysis and the expected output type
|
|
@@ -310,22 +379,32 @@ export declare class DocumentAnalysisClient {
|
|
|
310
379
|
* This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
|
|
311
380
|
* objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
|
|
312
381
|
*
|
|
313
|
-
* ```
|
|
314
|
-
* import
|
|
382
|
+
* ```ts snippet:ReadmeSampleClassifyDocument_File
|
|
383
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
384
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
385
|
+
* import { createReadStream } from "node:fs";
|
|
386
|
+
*
|
|
387
|
+
* const credential = new DefaultAzureCredential();
|
|
388
|
+
* const client = new DocumentAnalysisClient(
|
|
389
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
390
|
+
* credential,
|
|
391
|
+
* );
|
|
315
392
|
*
|
|
316
|
-
* const
|
|
393
|
+
* const path = "<path to a document>";
|
|
394
|
+
* const readStream = createReadStream(path);
|
|
317
395
|
*
|
|
318
|
-
* const poller = await client.beginClassifyDocument("<classifier
|
|
396
|
+
* const poller = await client.beginClassifyDocument("<classifier id>", readStream);
|
|
319
397
|
*
|
|
320
|
-
*
|
|
321
|
-
* const {
|
|
322
|
-
* pages, // pages extracted from the document, which contain only basic information for classifiers
|
|
323
|
-
* documents // extracted documents and their types
|
|
324
|
-
* } = await poller.pollUntilDone();
|
|
398
|
+
* const result = await poller.pollUntilDone();
|
|
325
399
|
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
400
|
+
* if (result?.documents?.length === 0) {
|
|
401
|
+
* throw new Error("Failed to extract any documents.");
|
|
402
|
+
* }
|
|
403
|
+
*
|
|
404
|
+
* for (const document of result.documents) {
|
|
405
|
+
* console.log(
|
|
406
|
+
* `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
|
|
407
|
+
* );
|
|
329
408
|
* }
|
|
330
409
|
* ```
|
|
331
410
|
*
|
|
@@ -351,21 +430,31 @@ export declare class DocumentAnalysisClient {
|
|
|
351
430
|
* token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
|
|
352
431
|
* request the file.
|
|
353
432
|
*
|
|
354
|
-
* ```
|
|
355
|
-
*
|
|
356
|
-
*
|
|
433
|
+
* ```ts snippet:ReadmeSampleClassifyDocument
|
|
434
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
435
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
357
436
|
*
|
|
358
|
-
* const
|
|
437
|
+
* const credential = new DefaultAzureCredential();
|
|
438
|
+
* const client = new DocumentAnalysisClient(
|
|
439
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
440
|
+
* credential,
|
|
441
|
+
* );
|
|
359
442
|
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
443
|
+
* const documentUrl =
|
|
444
|
+
* "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/invoice/Invoice_1.pdf";
|
|
445
|
+
*
|
|
446
|
+
* const poller = await client.beginClassifyDocumentFromUrl("<classifier id>", documentUrl);
|
|
447
|
+
*
|
|
448
|
+
* const result = await poller.pollUntilDone();
|
|
449
|
+
*
|
|
450
|
+
* if (result?.documents?.length === 0) {
|
|
451
|
+
* throw new Error("Failed to extract any documents.");
|
|
452
|
+
* }
|
|
365
453
|
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
454
|
+
* for (const document of result.documents) {
|
|
455
|
+
* console.log(
|
|
456
|
+
* `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
|
|
457
|
+
* );
|
|
369
458
|
* }
|
|
370
459
|
* ```
|
|
371
460
|
* @param classifierId - the ID of the custom classifier to use for analysis
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentAnalysisClient.d.ts","sourceRoot":"","sources":["../../src/documentAnalysisClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAUvE,OAAO,KAAK,EAEV,cAAc,EAGd,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAEpF
|
|
1
|
+
{"version":3,"file":"documentAnalysisClient.d.ts","sourceRoot":"","sources":["../../src/documentAnalysisClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -15,25 +15,27 @@ import { makeServiceClient, Mappers, SERIALIZER } from "./util.js";
|
|
|
15
15
|
*
|
|
16
16
|
* #### Azure Active Directory
|
|
17
17
|
*
|
|
18
|
-
* ```
|
|
19
|
-
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
18
|
+
* ```ts snippet:ReadmeSampleCreateClient_TokenCredential
|
|
20
19
|
* import { DefaultAzureCredential } from "@azure/identity";
|
|
20
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
21
21
|
*
|
|
22
|
-
* const endpoint = "https://<resource name>.cognitiveservices.azure.com";
|
|
23
22
|
* const credential = new DefaultAzureCredential();
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* const client = new DocumentAnalysisClient(
|
|
24
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
25
|
+
* credential,
|
|
26
|
+
* );
|
|
26
27
|
* ```
|
|
27
28
|
*
|
|
28
29
|
* #### API Key (Subscription Key)
|
|
29
30
|
*
|
|
30
|
-
* ```
|
|
31
|
-
* import {
|
|
31
|
+
* ```ts snippet:ReadmeSampleCreateClient_KeyCredential
|
|
32
|
+
* import { AzureKeyCredential, DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
32
33
|
*
|
|
33
|
-
* const
|
|
34
|
-
* const
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* const credential = new AzureKeyCredential("<API key>");
|
|
35
|
+
* const client = new DocumentAnalysisClient(
|
|
36
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
37
|
+
* credential,
|
|
38
|
+
* );
|
|
37
39
|
* ```
|
|
38
40
|
*/
|
|
39
41
|
export class DocumentAnalysisClient {
|
|
@@ -107,22 +109,32 @@ export class DocumentAnalysisClient {
|
|
|
107
109
|
* This method supports streamable request bodies ({@link FormRecognizerRequestBody}) such as Node.JS `ReadableStream`
|
|
108
110
|
* objects, browser `Blob`s, and `ArrayBuffer`s. The contents of the body will be uploaded to the service for analysis.
|
|
109
111
|
*
|
|
110
|
-
* ```
|
|
111
|
-
* import
|
|
112
|
+
* ```ts snippet:ReadmeSampleClassifyDocument_File
|
|
113
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
114
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
115
|
+
* import { createReadStream } from "node:fs";
|
|
116
|
+
*
|
|
117
|
+
* const credential = new DefaultAzureCredential();
|
|
118
|
+
* const client = new DocumentAnalysisClient(
|
|
119
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
120
|
+
* credential,
|
|
121
|
+
* );
|
|
112
122
|
*
|
|
113
|
-
* const
|
|
123
|
+
* const path = "<path to a document>";
|
|
124
|
+
* const readStream = createReadStream(path);
|
|
114
125
|
*
|
|
115
|
-
* const poller = await client.beginClassifyDocument("<classifier
|
|
126
|
+
* const poller = await client.beginClassifyDocument("<classifier id>", readStream);
|
|
116
127
|
*
|
|
117
|
-
*
|
|
118
|
-
* const {
|
|
119
|
-
* pages, // pages extracted from the document, which contain only basic information for classifiers
|
|
120
|
-
* documents // extracted documents and their types
|
|
121
|
-
* } = await poller.pollUntilDone();
|
|
128
|
+
* const result = await poller.pollUntilDone();
|
|
122
129
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
130
|
+
* if (result?.documents?.length === 0) {
|
|
131
|
+
* throw new Error("Failed to extract any documents.");
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* for (const document of result.documents) {
|
|
135
|
+
* console.log(
|
|
136
|
+
* `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
|
|
137
|
+
* );
|
|
126
138
|
* }
|
|
127
139
|
* ```
|
|
128
140
|
*
|
|
@@ -152,21 +164,31 @@ export class DocumentAnalysisClient {
|
|
|
152
164
|
* token can be used to grant read access to a blob in Azure Storage, and the service will use the SAS-encoded URL to
|
|
153
165
|
* request the file.
|
|
154
166
|
*
|
|
155
|
-
* ```
|
|
156
|
-
*
|
|
157
|
-
*
|
|
167
|
+
* ```ts snippet:ReadmeSampleClassifyDocument
|
|
168
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
169
|
+
* import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
|
|
170
|
+
*
|
|
171
|
+
* const credential = new DefaultAzureCredential();
|
|
172
|
+
* const client = new DocumentAnalysisClient(
|
|
173
|
+
* "https://<resource name>.cognitiveservices.azure.com",
|
|
174
|
+
* credential,
|
|
175
|
+
* );
|
|
176
|
+
*
|
|
177
|
+
* const documentUrl =
|
|
178
|
+
* "https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/invoice/Invoice_1.pdf";
|
|
158
179
|
*
|
|
159
|
-
* const poller = await client.
|
|
180
|
+
* const poller = await client.beginClassifyDocumentFromUrl("<classifier id>", documentUrl);
|
|
160
181
|
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* }
|
|
182
|
+
* const result = await poller.pollUntilDone();
|
|
183
|
+
*
|
|
184
|
+
* if (result?.documents?.length === 0) {
|
|
185
|
+
* throw new Error("Failed to extract any documents.");
|
|
186
|
+
* }
|
|
166
187
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
188
|
+
* for (const document of result.documents) {
|
|
189
|
+
* console.log(
|
|
190
|
+
* `Extracted a document with type '${document.docType}' on page ${document.boundingRegions?.[0].pageNumber} (confidence: ${document.confidence})`,
|
|
191
|
+
* );
|
|
170
192
|
* }
|
|
171
193
|
* ```
|
|
172
194
|
* @param classifierId - the ID of the custom classifier to use for analysis
|