
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@azure-rest/ai-document-intelligence
Advanced tools
Azure Document Intelligence Rest Client
Extracts content, layout, and structured data from documents.
Please rely heavily on our REST client docs to use this library
Key links:
@azure-rest/ai-document-intelligence
packageInstall the Azure DocumentIntelligence(formerlyFormRecognizer) REST client REST client library for JavaScript with npm
:
npm install @azure-rest/ai-document-intelligence
DocumentIntelligenceClient
To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.
To authenticate with AAD, you must first npm
install @azure/identity
After setup, you can choose which type of credential from @azure/identity
to use.
As an example, 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
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
const client = DocumentIntelligence(
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"],
new DefaultAzureCredential()
);
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
const client = DocumentIntelligence(process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"], {
key: process.env["DOCUMENT_INTELLIGENCE_API_KEY"],
});
const response = await client.path("/info").get();
if (isUnexpected(response)) {
throw response.body.error;
}
console.log(response.body.customDocumentModels.limit);
// 20000
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);
}
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" },
});
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
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'
// }
// }
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'
// }
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
:
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.
FAQs
Document Intelligence Rest Client
The npm package @azure-rest/ai-document-intelligence receives a total of 14,439 weekly downloads. As such, @azure-rest/ai-document-intelligence popularity was classified as popular.
We found that @azure-rest/ai-document-intelligence demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.