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

[Document Intelligence] Typespec Generated Code #27516

Merged
merged 56 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7402e68
typespec files added
HarshaNalluru Sep 26, 2023
1eb5f21
ai-documentintelligence typespec
HarshaNalluru Sep 27, 2023
4a7b203
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 23, 2023
07d4dc3
first draft of generated code using typespec
HarshaNalluru Oct 24, 2023
d451e2a
build conflicts
HarshaNalluru Oct 24, 2023
1f2f6fe
manual updates on geenrated code to fix build - build is green now
HarshaNalluru Oct 24, 2023
4261e58
4 functional live tests
HarshaNalluru Oct 24, 2023
f8eb647
rushx format
HarshaNalluru Oct 24, 2023
090d7be
concise
HarshaNalluru Oct 24, 2023
f1118b2
remove typespec references
HarshaNalluru Oct 24, 2023
5d003e1
with latest typespec from Paul
HarshaNalluru Oct 25, 2023
350c05a
ignore typespec files
HarshaNalluru Oct 25, 2023
ab6892b
build test
HarshaNalluru Oct 26, 2023
38febeb
latest generated code Nov 2nd
HarshaNalluru Nov 2, 2023
b1d6a5e
fix policy addition
HarshaNalluru Nov 2, 2023
4cc6f60
test files
HarshaNalluru Nov 3, 2023
65216ea
rename package and build
HarshaNalluru Nov 9, 2023
dc16243
latest typespec, build and format
HarshaNalluru Nov 9, 2023
516e02b
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Nov 9, 2023
ab5d36a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Nov 10, 2023
0ef1f0c
lock file from main
HarshaNalluru Nov 10, 2023
bef1b6a
lock file
HarshaNalluru Nov 10, 2023
8559979
tests and sample
HarshaNalluru Nov 10, 2023
930c94c
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Nov 16, 2023
d252f1e
src
HarshaNalluru Nov 16, 2023
9c28257
generate again
HarshaNalluru Nov 16, 2023
4ef6e23
format
HarshaNalluru Nov 16, 2023
96427f9
format test
HarshaNalluru Nov 16, 2023
3e667fd
analysis.spec.ts done
HarshaNalluru Nov 16, 2023
fbe7939
classifiers.spec.ts
HarshaNalluru Nov 16, 2023
66cd873
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Nov 16, 2023
0f00d9f
lock file
HarshaNalluru Nov 16, 2023
cef7fc7
Merge branch 'main' into harshan/typespec-fr
HarshaNalluru Nov 16, 2023
87e3211
Merge branch 'harshan/typespec-fr' of https://github.com/harshanallur…
HarshaNalluru Nov 16, 2023
9eb4f6b
port training.spec.ts
HarshaNalluru Nov 16, 2023
d855606
format
HarshaNalluru Nov 16, 2023
56bfe3f
revert gitignore
HarshaNalluru Nov 16, 2023
8f18262
address feedback
HarshaNalluru Nov 16, 2023
e529021
pushed recordings
HarshaNalluru Nov 16, 2023
a9d1f82
recorder options
HarshaNalluru Nov 16, 2023
f2087b1
push assets
HarshaNalluru Nov 16, 2023
d03c60a
potential arm-template
HarshaNalluru Nov 16, 2023
ab13288
test-resources without AAD
HarshaNalluru Nov 16, 2023
dbc8a28
yml files - pipelines
HarshaNalluru Nov 16, 2023
f6021a5
samples-dev
HarshaNalluru Nov 16, 2023
4ac8495
fix samples
HarshaNalluru Nov 16, 2023
d6bf23d
sample.env
HarshaNalluru Nov 16, 2023
a6cf88d
samples generated
HarshaNalluru Nov 16, 2023
ba9a562
changelog and readme
HarshaNalluru Nov 16, 2023
b79a52c
cspell
HarshaNalluru Nov 16, 2023
1b023f7
more feedback
HarshaNalluru Nov 16, 2023
ba2fc94
format
HarshaNalluru Nov 16, 2023
63f7966
echo skipped browser
HarshaNalluru Nov 16, 2023
e3e175a
assets
HarshaNalluru Nov 16, 2023
7d2a2a1
fix broken links
HarshaNalluru Nov 16, 2023
3b25e49
unquote
HarshaNalluru Nov 16, 2023
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
8 changes: 8 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@
"Whois",
"whois"
]
},
{
"filename": "sdk/documentintelligence/ai-document-intelligence-rest/review/ai-document-intelligence.api.md",
"words": [
"wordprocessingml",
"spreadsheetml",
"presentationml"
]
}
]
}
58 changes: 53 additions & 5 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@
"projectFolder": "sdk/agrifood/agrifood-farming-rest",
"versionPolicyName": "client"
},
{
"packageName": "@azure-rest/ai-document-intelligence",
"projectFolder": "sdk/documentintelligence/ai-document-intelligence-rest",
"versionPolicyName": "client"
},
{
"packageName": "@azure-rest/purview-administration",
"projectFolder": "sdk/purview/purview-administration-rest",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": ["@azure/azure-sdk"],
"extends": ["plugin:@azure/azure-sdk/azure-sdk-base"],
"rules": {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Release History

## 1.0.0-beta.1 (2023-11-16)

### Features Added

This marks the first preview of `@azure-rest/ai-document-intelligence` Rest Level Client Library for the Azure AI Document Intelligence service (formerly known as Form Recognizer).
Please refer to the [Readme](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/documentintelligence/ai-document-intelligence-rest/README.md) and samples for more details.
224 changes: 224 additions & 0 deletions sdk/documentintelligence/ai-document-intelligence-rest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# Azure DocumentIntelligence (formerly FormRecognizer) REST client library for JavaScript
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved

Extracts content, layout, and structured data from documents.

**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**

Key links:

- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest)
- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/ai-document-intelligence)
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documentintelligence/ai-document-intelligence-rest/samples)

## Getting started

### Currently supported environments

- LTS versions of Node.js

### Prerequisites

- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.

### Install the `@azure-rest/ai-document-intelligence` package

Install the Azure DocumentIntelligence(formerlyFormRecognizer) REST client REST client library for JavaScript with `npm`:

```bash
npm install @azure-rest/ai-document-intelligence
```

### Create and authenticate a `DocumentIntelligenceClient`

To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
provide an instance of the desired credential type obtained from the
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.

To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)

After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
can be used to authenticate the client.

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

### Using a Token Credential

```ts
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";

const client = DocumentIntelligence(
HarshaNalluru marked this conversation as resolved.
Show resolved Hide resolved
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
new DefaultAzureCredential()
);
```

### Using an API KEY

```ts
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";

const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
key: process.env["DOCUMENT_INTELLIGENCE_API_KEY"],
});
```

## Get Info

```ts
const response = await client.path("/info").get();
if (isUnexpected(response)) {
throw response.body.error;
}
console.log(response.body.customDocumentModels.limit);
// 20000
```

## List Document Models

```ts
import { paginate } from "@azure-rest/ai-document-intelligence";
const response = await client.path("/documentModels").get();
if (isUnexpected(response)) {
throw response.body.error;
}

const modelsInAccount: string[] = [];
for await (const model of paginate(client, response)) {
console.log(model.modelId);
}
```

## Document Models

### Analyze prebuilt-layout (urlSource)

```ts
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
.post({
contentType: "application/json",
body: {
urlSource:
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/6704eff082aaaf2d97c1371a28461f512f8d748a/sdk/formrecognizer/ai-form-recognizer/assets/forms/Invoice_1.pdf",
},
queryParameters: { locale: "en-IN" },
});
```

### Analyze prebuilt-layout (base64Source)

```ts
import fs from "fs";
import path from "path";

const filePath = path.join(ASSET_PATH, "forms", "Invoice_1.pdf");
const base64Source = fs.readFileSync(filePath, { encoding: "base64" });
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
.post({
contentType: "application/json",
body: {
base64Source,
},
queryParameters: { locale: "en-IN" },
});
```

Continue creating the poller from initial response

```ts
import {
getLongRunningPoller,
AnalyzeResultOperationOutput,
isUnexpected,
} from "@azure-rest/ai-document-intelligence";

if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
const poller = await getLongRunningPoller(client, initialResponse);
const result = (await poller.pollUntilDone()).body as AnalyzeResultOperationOutput;
console.log(result);
// {
// status: 'succeeded',
// createdDateTime: '2023-11-10T13:31:31Z',
// lastUpdatedDateTime: '2023-11-10T13:31:34Z',
// analyzeResult: {
// apiVersion: '2023-10-31-preview',
// .
// .
// .
// contentFormat: 'text'
// }
// }
```

## Document Classifiers #Build

```ts
import {
DocumentClassifierBuildOperationDetailsOutput,
getLongRunningPoller,
isUnexpected,
} from "@azure-rest/ai-document-intelligence";

const containerSasUrl = (): string =>
process.env["DOCUMENT_INTELLIGENCE_TRAINING_CONTAINER_SAS_URL"];
const initialResponse = await client.path("/documentClassifiers:build").post({
body: {
classifierId: `customClassifier${getRandomNumber()}`,
description: "Custom classifier description",
docTypes: {
foo: {
azureBlobSource: {
containerUrl: containerSasUrl(),
},
},
bar: {
azureBlobSource: {
containerUrl: containerSasUrl(),
},
},
},
},
});

if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
const poller = await getLongRunningPoller(client, initialResponse);
const response = (await poller.pollUntilDone())
.body as DocumentClassifierBuildOperationDetailsOutput;
console.log(response);
// {
// operationId: '31466834048_f3ee629e-73fb-48ab-993b-1d55d73ca460',
// kind: 'documentClassifierBuild',
// status: 'succeeded',
// .
// .
// result: {
// classifierId: 'customClassifier10978',
// createdDateTime: '2023-11-09T12:45:56Z',
// .
// .
// description: 'Custom classifier description'
// },
// apiVersion: '2023-10-31-preview'
// }
```

## Troubleshooting

### Logging

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

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).
Loading