Files
Deyaaeldeen AlmahallawiandGitHub 07131a27f7 [document intelligence] Use safe secrets (#33551)
Overhauls tests and samples for Azure Cognitive Services for Language
SDKs by implementing safe secret standards:
- Updates `test-resources.bicep` to not output API keys nor SAS tokens
- Updates the tests to retrieve API keys using the arm client
- Updates the tests to create SAS tokens for Storage container access
- Updates the samples and snippets to use Entra ID authentication
- Fix live tests by enabling SAS access to the persistent storage
account

Live tests run:
https://dev.azure.com/azure-sdk/internal/_build/results?buildId=4694655&view=results
2025-03-27 17:02:52 -07:00

49 lines
1.5 KiB
TypeScript

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample shows how to iterate over the models in a resource. This will include both custom and prebuilt models.
*
* @summary iterate over the models in a resource
*/
import DocumentIntelligence, { isUnexpected, paginate } from "@azure-rest/ai-document-intelligence";
import { DefaultAzureCredential } from "@azure/identity";
import "dotenv/config";
async function main(): Promise<void> {
const client = DocumentIntelligence(
process.env["DOCUMENT_INTELLIGENCE_ENDPOINT"] || "<cognitive services endpoint>",
new DefaultAzureCredential(),
);
const response = await client.path("/documentModels").get();
if (isUnexpected(response)) {
throw response.body.error;
}
for await (const model of paginate(client, response)) {
console.log("- ID", model.modelId);
console.log(" Created:", model.createdDateTime);
console.log(" Description: ", model.description || "<none>");
// The model summary does not include `docTypes`, so we must additionally call `getModel` to retrieve them
const detailedModel = await client.path("/documentModels/{modelId}", model.modelId).get();
if (isUnexpected(detailedModel)) {
throw detailedModel.body.error;
}
const docTypes = detailedModel.body.docTypes;
console.log(" Document Types:");
for (const docType of Object.keys(docTypes || {})) {
console.log(" -", docType);
}
}
}
main().catch((error) => {
console.error("An error occurred:", error);
process.exit(1);
});