Skip to content

Commit a9966ca

Browse files
Merge pull request #276369 from laujan/patch-1
Update javascript-sdk.md
2 parents 3627702 + 20b48b8 commit a9966ca

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

articles/ai-services/document-intelligence/quickstarts/includes/javascript-sdk.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
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"
33
titleSuffix: Azure AI services
44
description: Form and document processing, data extraction, and analysis using Document Intelligence JavaScript client library.
55
author: laujan
@@ -73,8 +73,7 @@ In this quickstart, use the following features to analyze and extract data and v
7373
4. Install the `ai-document-intelligence` client library and `azure/identity` npm packages:
7474

7575
```console
76-
npm i @azure-rest/[email protected] @azure/identity
77-
76+
npm i @azure-rest/[email protected] @azure/core-auth
7877
```
7978

8079
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
119118

120119
:::moniker range="doc-intel-3.1.0 || doc-intel-3.0.0"
121120

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
123122
Recognizer `endpoint`.
124123

125124
:::moniker-end
@@ -146,7 +145,10 @@ Extract text, selection marks, text styles, table structures, and bounding regio
146145
:::moniker range="doc-intel-4.0.0"
147146

148147
```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");
150152

151153
// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
152154
const key = "<your-key";
@@ -156,7 +158,7 @@ Extract text, selection marks, text styles, table structures, and bounding regio
156158
const formUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"
157159

158160
async function main() {
159-
const client = DocumentIntelligenceClient(endpoint, {key:key},);
161+
const client = DocumentIntelligence(endpoint, new AzureKeyCredential(key:key));
160162

161163

162164
const initialResponse = await client
@@ -168,6 +170,10 @@ Extract text, selection marks, text styles, table structures, and bounding regio
168170
},
169171
});
170172

173+
if (isUnexpected(initialResponse)) {
174+
throw initialResponse.body.error;
175+
}
176+
171177
const poller = await getLongRunningPoller(client, initialResponse);
172178
const analyzeResult = (await poller.pollUntilDone()).body.analyzeResult;
173179

@@ -309,19 +315,21 @@ In this example, we analyze an invoice using the **prebuilt-invoice** model.
309315

310316
```javascript
311317

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");
313322

314323
// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
315324
const key = "<your-key>";
316325
const endpoint = "<your-endpoint>";
317326

318327
// 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"
320329

321330
async function main() {
322331

323-
const client = DocumentIntelligenceClient(endpoint, {key: key},
324-
);
332+
const client = DocumentIntelligence(endpoint, new AzureKeyCredential(key:key));
325333

326334
const initialResponse = await client
327335
.path("/documentModels/{modelId}:analyze", "prebuilt-invoice")
@@ -333,6 +341,9 @@ async function main() {
333341
},
334342
});
335343

344+
if (isUnexpected(initialResponse)) {
345+
throw initialResponse.body.error;
346+
}
336347

337348
const poller = await getLongRunningPoller(client, initialResponse);
338349

0 commit comments

Comments
 (0)