1
1
---
2
- title : " Quickstart: Document Intelligence (formerly Form Recognizer) JavaScript SDK (beta) | v3.1 | v3.0 "
2
+ title : " Quickstart: Document Intelligence (formerly Form Recognizer) JavaScript SDK"
3
3
titleSuffix : Azure AI services
4
4
description : Form and document processing, data extraction, and analysis using Document Intelligence JavaScript client library.
5
5
author : laujan
@@ -73,8 +73,7 @@ In this quickstart, use the following features to analyze and extract data and v
73
73
4. Install the `ai-document-intelligence` client library and `azure/identity` npm packages:
74
74
75
75
```console
76
- npm i @azure-rest/[email protected] @azure/identity
77
-
76
+ npm i @azure-rest/[email protected] @azure/core-auth
78
77
```
79
78
80
79
Your app's `package.json` file is updated with the dependencies.
@@ -119,7 +118,7 @@ To interact with the Document Intelligence service, you need to create an instan
119
118
120
119
:::moniker range="doc-intel-3.1.0 || doc-intel-3.0.0"
121
120
122
- To interact with the Document Intelligence service, you need to create an instance of the `DocumentAnalysisClient` class. To do so, you create an `AzureKeyCredential` with your `key` from the Azure portal and a `DocumentAnalysisClient` instance with the `AzureKeyCredential` and your Form
121
+ To interact with the Document Intelligence service, you need to create an instance of the `DocumentAnalysisClient` class. To do so, you create an `AzureKeyCredential` with your `key` from the Azure portal and a `DocumentAnalysisClient` instance with the `AzureKeyCredential` and your Form
123
122
Recognizer `endpoint`.
124
123
125
124
:::moniker-end
@@ -146,7 +145,10 @@ Extract text, selection marks, text styles, table structures, and bounding regio
146
145
:::moniker range="doc-intel-4.0.0"
147
146
148
147
```javascript
149
- const DocumentIntelligenceClient = require("@azure-rest/ai-document-intelligence");
148
+ const DocumentIntelligence = require("@azure-rest/ai-document-intelligence").default,
149
+ { getLongRunningPoller, isUnexpected } = require("@azure-rest/ai-document-intelligence");
150
+
151
+ const { AzureKeyCredential } = require("@azure/core-auth");
150
152
151
153
// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
152
154
const key = "<your-key";
@@ -156,7 +158,7 @@ Extract text, selection marks, text styles, table structures, and bounding regio
156
158
const formUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"
157
159
158
160
async function main() {
159
- const client = DocumentIntelligenceClient (endpoint, { key:key}, );
161
+ const client = DocumentIntelligence (endpoint, new AzureKeyCredential( key:key) );
160
162
161
163
162
164
const initialResponse = await client
@@ -168,6 +170,10 @@ Extract text, selection marks, text styles, table structures, and bounding regio
168
170
},
169
171
});
170
172
173
+ if (isUnexpected(initialResponse)) {
174
+ throw initialResponse.body.error;
175
+ }
176
+
171
177
const poller = await getLongRunningPoller(client, initialResponse);
172
178
const analyzeResult = (await poller.pollUntilDone()).body.analyzeResult;
173
179
@@ -309,19 +315,21 @@ In this example, we analyze an invoice using the **prebuilt-invoice** model.
309
315
310
316
``` javascript
311
317
312
- const DocumentIntelligenceClient = require (" @azure-rest/ai-document-intelligence" );
318
+ const DocumentIntelligence = require (" @azure-rest/ai-document-intelligence" ).default ,
319
+ { getLongRunningPoller, isUnexpected } = require (" @azure-rest/ai-document-intelligence" );
320
+
321
+ const { AzureKeyCredential } = require (" @azure/core-auth" );
313
322
314
323
// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
315
324
const key = " <your-key>" ;
316
325
const endpoint = " <your-endpoint>" ;
317
326
318
327
// sample document
319
- invoiceUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
328
+ const invoiceUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
320
329
321
330
async function main () {
322
331
323
- const client = DocumentIntelligenceClient (endpoint, {key: key},
324
- );
332
+ const client = DocumentIntelligence (endpoint, new AzureKeyCredential (key: key));
325
333
326
334
const initialResponse = await client
327
335
.path (" /documentModels/{modelId}:analyze" , " prebuilt-invoice" )
@@ -333,6 +341,9 @@ async function main() {
333
341
},
334
342
});
335
343
344
+ if (isUnexpected (initialResponse)) {
345
+ throw initialResponse .body .error ;
346
+ }
336
347
337
348
const poller = await getLongRunningPoller (client, initialResponse);
338
349
0 commit comments