From a491c5696ca9a18c790ac42a78db84c72af1c1cc Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Mon, 16 Dec 2024 16:24:47 -0800 Subject: [PATCH] [DocumentIntelligence] 1.0.0: finishing docs and samples updates (#47585) --- .../CHANGELOG.md | 2 +- .../MigrationGuide.md | 44 ++++----- .../Azure.AI.DocumentIntelligence/README.md | 92 +++++++++---------- .../samples/Sample_AddOnCapabilities.md | 6 +- .../Sample_AnalyzeWithPrebuiltModel.md | 11 +-- .../samples/Sample_BuildCustomModel.md | 6 +- .../samples/Sample_BuildDocumentClassifier.md | 6 +- .../samples/Sample_ClassifyDocument.md | 6 +- .../samples/Sample_CopyCustomModel.md | 8 +- .../samples/Sample_ExtractLayout.md | 11 +-- .../samples/Sample_ExtractLayoutAsMarkdown.md | 8 +- .../samples/Sample_GetAndListOperations.md | 15 ++- .../samples/Sample_ManageModels.md | 6 +- .../samples/Sample_ModelCompose.md | 6 +- .../src/DocumentIntelligenceClientOptions.cs | 27 ++++++ .../DocumentIntelligenceClientOptions.cs | 10 -- .../src/GeneratorStubs/PublicTypes.cs | 3 - ...mple_AnalyzeWithPrebuiltModelFromBytes.cs} | 6 +- .../Sample_AnalyzeWithPrebuiltModelFromUri.cs | 5 +- .../Sample_ExtractLayoutFromUriAsync.cs | 5 +- .../Sample_GetAndListOperationsAsync.cs | 4 + 21 files changed, 142 insertions(+), 145 deletions(-) create mode 100644 sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/DocumentIntelligenceClientOptions.cs rename sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/{SampleAnalyzeWithPrebuiltModelFromBytes.cs => Sample_AnalyzeWithPrebuiltModelFromBytes.cs} (96%) diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/CHANGELOG.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/CHANGELOG.md index 005a6a8817fa..c32bf4c2f107 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/CHANGELOG.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0 (2024-12-17) +## 1.0.0 (2024-12-16) ### Features Added - Added methods `GetAnalyzeBatchResult`, `GetAnalyzeBatchResults`, `DeleteAnalyzeBatchResult`, and `DeleteAnalyzeResult` to `DocumentIntelligenceClient`. diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/MigrationGuide.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/MigrationGuide.md index a4c28271a20a..606e11f0cfda 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/MigrationGuide.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/MigrationGuide.md @@ -2,7 +2,7 @@ This guide is intended to assist in the migration to `Azure.AI.DocumentIntelligence (1.0.0)` from `Azure.AI.FormRecognizer (4.1.0 or 4.0.0)`. It will focus on side-by-side comparisons for similar operations between libraries. Please note that version `1.0.0` will be used for comparison with `4.1.0`. -Familiarity with the `Azure.AI.FormRecognizer` package is assumed. For those new to the Document Intelligence and the Form Recognizer client libraries for .NET, please refer to the [README][readme] rather than this guide. For an exhaustive list of breaking changes between the packages, see the [CHANGELOG][changelog]. +Familiarity with the `Azure.AI.FormRecognizer` package is assumed. For those new to the Document Intelligence and the Form Recognizer client libraries for .NET, please refer to the [README][readme] rather than this guide. ## Table of Contents - [Migration benefits](#migration-benefits) @@ -26,11 +26,12 @@ There are many benefits to using the new `Azure.AI.DocumentIntelligence` library New features provided by the `Azure.AI.DocumentIntelligence` library include: - **Markdown content format:** support to output with Markdown content format along with the default plain text. This is only supported for the "prebuilt-layout" model. Markdown content format is deemed a more friendly format for LLM consumption in a chat or automation use scenario. -- **Query fields:** query fields are reintroduced as a premium add-on feature. When the `DocumentAnalysisFeature.QueryFields` argument is passed to a document analysis request, the service will further extract the values of the fields specified via the parameter `queryFields` to supplement any existing fields defined by the model as fallback. -- **Split options:** in previous API versions, the document splitting and classification operation always tried to split the input file into multiple documents. To enable a wider set of scenarios, `ClassifyDocument` now supports a `split` parameter. The following values are supported: +- **Query fields:** query fields are reintroduced as a premium add-on feature. When the `DocumentAnalysisFeature.QueryFields` argument is passed to a document analysis request, the service will further extract the values of the fields specified via the option `QueryFields` to supplement any existing fields defined by the model as fallback. +- **Split options:** in previous API versions, the document splitting and classification operation always tried to split the input file into multiple documents. To enable a wider set of scenarios, `ClassifyDocument` now supports a `Split` option. The following values are supported: - `Auto`: let the service determine where to split. - `None`: the entire file is treated as a single document. No splitting is performed. - `PerPage`: each page is treated as a separate document. Each empty page is kept as its own document. +- **Batch analysis:** allows you to bulk process multiple documents using a single request. Rather than having to submit documents individually, you can analyze a collection of documents like invoices, a series of a loan documents, or a group of custom documents simultaneously. The table below describes the relationship of each client and its supported API version(s): @@ -57,10 +58,7 @@ Some terminology has changed to reflect the enhanced capabilities of the latest ### Client usage -We continue to support API key and AAD authentication methods when creating the clients. Below are the differences between the two versions: - -- In `Azure.AI.DocumentIntelligence`, we have `DocumentIntelligenceClient` and `DocumentIntelligenceAdministrationClient` which support API version `2024-11-30` and higher. -- Some client methods have been renamed. See the [CHANGELOG][changelog] for an exhaustive list of changes. +In `Azure.AI.DocumentIntelligence`, we have `DocumentIntelligenceClient` and `DocumentIntelligenceAdministrationClient` which can only be used with API version `2024-11-30` and higher. We continue to support Microsoft Entra ID and API key authentication methods when creating the clients: Creating new clients in `Azure.AI.FormRecognizer`: ```C# @@ -83,10 +81,10 @@ var documentIntelligenceAdministrationClient = new DocumentIntelligenceAdministr ### Analyzing documents Differences between the versions: -- The former `AnalyzeDocument` method taking a `Stream` as the input document is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. As a workaround you will need to use a URI input or the new Base64 input option, which is described later in this guide ([Analyzing and classifying documents from a stream](#analyzing-and-classifying-documents-from-a-stream)). -- `AnalyzeDocumentFromUri` has been renamed to `AnalyzeDocument` and its input arguments have been reorganized: - - The `documentUri` parameter has been removed. Instead, an `AnalyzeDocumentContent` object must be passed to the method to select the desired input type: URI or Base64 binary data. - - The `options` parameter has been removed. Instead, `pages`, `locale`, and `features` options can be passed directly as method parameters. +- The former `AnalyzeDocument` method taking a `Stream` as the input document is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. As a workaround you will need to use a URI input or the new binary data input option, which is described later in this guide ([Analyzing and classifying documents from a stream](#analyzing-and-classifying-documents-from-a-stream)). +- `AnalyzeDocumentFromUri` has been renamed to `AnalyzeDocument`. + - The `modelId` and the `documentUri` parameters have been moved into `AnalyzeDocumentOptions`, which is now required. The desired input type must be selected when creating the options object: URI or binary data. +- Overloads of `AnalyzeDocument` have been added to support simpler scenarios without creating an `AnalyzeDocumentOptions` object. - The property `DocumentField.Value` has been removed. A field's value can now be extracted from one of the its new value properties, depending on the type of the field: `ValueAddress` for type `Address`, `ValueBoolean` for type `Boolean`, and so on. Analyzing documents with `Azure.AI.FormRecognizer`: @@ -214,10 +212,7 @@ if (invoice.Fields.TryGetValue("InvoiceTotal", out FormField invoiceTotalField)) Analyzing documents with `Azure.AI.DocumentIntelligence`: ```C# Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelFromUriAsync Uri uriSource = new Uri(""); - -var options = new AnalyzeDocumentOptions("prebuilt-invoice", uriSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", uriSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the @@ -298,8 +293,9 @@ for (int i = 0; i < result.Documents.Count; i++) ### Classifying documents Differences between the versions: -- The former `ClassifyDocument` method taking a `Stream` as the input document is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. As a workaround you will need to use a URI input or the new Base64 input option, which is described later in this guide ([Analyzing and classifying documents from a stream](#analyzing-and-classifying-documents-from-a-stream)). -- `ClassifyDocumentFromUri` has been renamed to `ClassifyDocument` and its input arguments have been reorganized. The `documentUri` parameter has been removed. Instead, a `ClassifyDocumentContent` object must be passed to the method to select the desired input type: URI or Base64 binary data. +- The former `ClassifyDocument` method taking a `Stream` as the input document is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. As a workaround you will need to use a URI input or the new binary data input option, which is described later in this guide ([Analyzing and classifying documents from a stream](#analyzing-and-classifying-documents-from-a-stream)). +- `ClassifyDocumentFromUri` has been renamed to `ClassifyDocument`: + - The `classifierId` and the `documentUri` parameters have been moved into a new `ClassifyDocumentOptions` property bag. The desired input type must be selected when creating the options object: URI or binary data. Classifying documents with `Azure.AI.FormRecognizer`: ```C# @@ -338,8 +334,8 @@ foreach (AnalyzedDocument document in result.Documents) ### Building a document model Differences between the versions: -- Parameters `trainingDataSource`, `buildMode`, `modelId`, and `options` have been removed. The method now takes a `buildRequest` parameter of type `BuildDocumentModelContent` containing all the removed options. -- After creating a `BuildDocumentModelContent` instance, either property `AzureBlobSource` or `AzureBlobFileListSource` must be set depending on your data source. +- Parameters `trainingDataSource`, `buildMode`, `modelId` have moved into `BuildDocumentModelOptions`, which is now required. +- When creating a `BuildDocumentModelOptions` instance, either property `BlobSource` or `BlobFileListSource` must be set depending on your data source. Building a document model with `Azure.AI.FormRecognizer`: ```C# @@ -404,16 +400,14 @@ foreach (KeyValuePair docType in model.DocumentType ### Analyzing and classifying documents from a stream -Currently neither `AnalyzeDocument` nor `ClassifyDocument` support submitting a document from a `Stream` input. As a temporary workaround, you can make use of the new Base64 input option. The following example illustrates how to submit a local file for analysis: +Currently neither `AnalyzeDocument` nor `ClassifyDocument` support submitting a document from a `Stream` input. As a temporary workaround, you can make use of the new binary data input option. The following example illustrates how to submit a local file for analysis: ```C# Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelFromBytesAsync string filePath = ""; byte[] fileBytes = File.ReadAllBytes(filePath); -var bytesSource = BinaryData.FromBytes(fileBytes); -var options = new AnalyzeDocumentOptions("prebuilt-invoice", bytesSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +BinaryData bytesSource = BinaryData.FromBytes(fileBytes); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", bytesSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the @@ -546,7 +540,7 @@ foreach (DocumentLine line in firstPage.Lines) ### Accessing an existing long-running operation -Storing the ID of a long-running operation to retrieve its status at a later point in time is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. There are no straightforward workarounds to support this scenario. +With the exception of the new batch analysis API, storing the ID of a long-running operation to retrieve its status at a later point in time is still not supported in `Azure.AI.DocumentIntelligence` 1.0.0. There are no straightforward workarounds to support this scenario. ## Additional samples diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/README.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/README.md index ab6b657e0f6c..ffde27092265 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/README.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/README.md @@ -14,8 +14,6 @@ Azure AI Document Intelligence is a cloud service that uses machine learning to ## Getting started -This section should include everything a developer needs to do to install and create their first client connection *very quickly*. - ### Install the package Install the Azure Document Intelligence client library for .NET with [NuGet][nuget]: @@ -29,15 +27,15 @@ dotnet add package Azure.AI.DocumentIntelligence ### Prerequisites * An [Azure subscription][azure_sub]. -* A [Cognitive Services or Document Intelligence resource][cognitive_resource] to use this package. +* A [Document Intelligence][docint_resource] or an [Azure AI services][ai_resource] resource to use this package. -#### Create a Cognitive Services or Document Intelligence resource +#### Create a Document Intelligence or an Azure AI services resource -Document Intelligence supports both [multi-service and single-service access][cognitive_resource_portal]. Create a Cognitive Services resource if you plan to access multiple cognitive services under a single endpoint and key. For Document Intelligence access only, create a Document Intelligence resource. Please note that you will need a single-service resource if you intend to use [Azure Active Directory authentication](#create-documentintelligenceclient-with-azure-active-directory-credential). +Document Intelligence supports both [multi-service and single-service access][ai_resource]. Create an Azure AI services resource if you plan to access multiple Azure AI services under a single endpoint and key. For Document Intelligence access only, create a Document Intelligence resource. Please note that you will need a single-service resource if you intend to use [Microsoft Entra ID authentication](#create-documentintelligenceclient-with-microsoft-entra-id). You can create either resource using: -* Option 1: [Azure Portal][cognitive_resource_portal]. +* Option 1: [Azure Portal][ai_resource]. * Option 2: [Azure CLI][cognitive_resource_cli]. Below is an example of how you can create a Document Intelligence resource using the CLI: @@ -49,7 +47,7 @@ az group create --name --location ``` ```PowerShell -# Create the Form Recognizer resource +# Create the Document Intelligence resource az cognitiveservices account create \ --name \ --resource-group \ @@ -81,46 +79,48 @@ Regional endpoint: https://.api.cognitive.microsoft.com/ Custom subdomain: https://.cognitiveservices.azure.com/ ``` -A regional endpoint is the same for every resource in a region. A complete list of supported regional endpoints can be consulted [here][regional_endpoints]. Please note that regional endpoints do not support AAD authentication. +A regional endpoint is the same for every resource in a region. A complete list of supported regional endpoints can be consulted [here][regional_endpoints]. Please note that regional endpoints do not support Microsoft Entra ID authentication. -A custom subdomain, on the other hand, is a name that is unique to the Document Intelligence resource. They can only be used by [single-service resources][cognitive_resource_portal]. +A custom subdomain, on the other hand, is a name that is unique to the Document Intelligence resource. They can only be used by [single-service resources][ai_resource]. -#### Get the API Key +#### Create DocumentIntelligenceClient with Microsoft Entra ID -The API key can be found in the [Azure Portal][azure_portal] or by running the following Azure CLI command: +You can authenticate with Microsoft Entra ID by using the [Azure Identity library][azure_identity]. Note that regional endpoints do not support identity-based authentication. Create a [custom subdomain][custom_subdomain] for your resource in order to use this type of authentication. -```PowerShell -az cognitiveservices account keys list --name "" --resource-group "" +To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `Azure.Identity` package: + +```dotnetcli +dotnet add package Azure.Identity ``` -#### Create DocumentIntelligenceClient with AzureKeyCredential +You will also need to [register a new Microsoft Entra application][register_aad_app] and grant access to Document Intelligence by assigning the `"Cognitive Services Data Reader"` role to your service principal. -Once you have the value for the API key, create an `AzureKeyCredential`. With the endpoint and key credential, you can create the [`DocumentIntelligenceClient`][doc_intelligence_client_class]: - -```C# Snippet:CreateDocumentIntelligenceClientApiKey +```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; -string apiKey = ""; -var client = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); +var credential = new DefaultAzureCredential(); +var client = new DocumentIntelligenceClient(new Uri(endpoint), credential); ``` -#### Create DocumentIntelligenceClient with Azure Active Directory Credential +#### Create DocumentIntelligenceClient with AzureKeyCredential + +It is strongly recommended to use Microsoft Entra ID as your default authentication approach. On the other hand, using an `AzureKeyCredential` can be helpful on getting-started scenarios since it can be set up fastly. -`AzureKeyCredential` authentication is used in the examples in this getting started guide, but you can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. Note that regional endpoints do not support AAD authentication. Create a [custom subdomain][custom_subdomain] for your resource in order to use this type of authentication. +##### Get the API Key -To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `Azure.Identity` package: +The API key can be found in the [Azure Portal][azure_portal_get_endpoint] or by running the following Azure CLI command: -```dotnetcli -dotnet add package Azure.Identity +```PowerShell +az cognitiveservices account keys list --name "" --resource-group "" ``` -You will also need to [register a new AAD application][register_aad_app] and [grant access][aad_grant_access] to Document Intelligence by assigning the `"Cognitive Services User"` role to your service principal. +##### Create 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. +Once you have the value for the API key, create an `AzureKeyCredential`. With the endpoint and key credential, you can create the [`DocumentIntelligenceClient`][doc_intelligence_client_class]: -```C# Snippet:CreateDocumentIntelligenceClient +```C# Snippet:CreateDocumentIntelligenceClientApiKey string endpoint = ""; -var credential = new DefaultAzureCredential(); -var client = new DocumentIntelligenceClient(new Uri(endpoint), credential); +string apiKey = ""; +var client = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); ``` ## Key concepts @@ -182,10 +182,7 @@ Extract text, selection marks, table structures, styles, and paragraphs, along w ```C# Snippet:DocumentIntelligenceExtractLayoutFromUriAsync Uri uriSource = new Uri(""); - -var options = new AnalyzeDocumentOptions("prebuilt-layout", uriSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", uriSource); AnalyzeResult result = operation.Value; foreach (DocumentPage page in result.Pages) @@ -281,10 +278,7 @@ For example, to analyze fields from an invoice, use the prebuilt Invoice model p ```C# Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelFromUriAsync Uri uriSource = new Uri(""); - -var options = new AnalyzeDocumentOptions("prebuilt-invoice", uriSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", uriSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the @@ -518,7 +512,7 @@ For more information, see [here][classify_document]. ### General -When you interact with the Document Intelligence client library using the .NET SDK, errors returned by the service will result in a `RequestFailedException` with the same HTTP status code returned by the [REST API][docint_rest_api] request. +When you interact with the Document Intelligence client library using the .NET SDK, errors returned by the service will result in a `RequestFailedException` with the same HTTP status code returned by the REST API request. For example, if you submit a receipt image with an invalid `Uri`, a `400` error is returned, indicating "Bad Request". @@ -548,12 +542,15 @@ Content: {"error":{"code":"InvalidRequest","message":"Invalid request.","innererror":{"code":"InvalidContent","message":"The file is corrupted or format is unsupported. Refer to documentation for the list of supported formats."}}} Headers: - Transfer-Encoding: chunked + ms-azure-ai-errorcode: REDACTED + x-ms-error-code: REDACTED x-envoy-upstream-service-time: REDACTED - apim-request-id: REDACTED + apim-request-id: 4ca2a2ff-aaa5-4ffa-864f-cbd8f4a847f7 Strict-Transport-Security: REDACTED X-Content-Type-Options: REDACTED - Date: Fri, 01 Oct 2021 02:55:44 GMT + x-ms-region: REDACTED + Date: Mon, 16 Dec 2024 23:25:15 GMT + Content-Length: 221 Content-Type: application/json; charset=utf-8 ``` @@ -601,27 +598,25 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [docint_client_src]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src [docint_docs]: https://learn.microsoft.com/azure/cognitive-services/form-recognizer/ -[docint_refdocs]: https://aka.ms/azsdk/net/docs/ref/formrecognizer -[docint_nuget_package]: https://www.nuget.org/packages/Azure.AI.FormRecognizer +[docint_refdocs]: https://learn.microsoft.com/dotnet/api/overview/azure/cognitiveservices/documentintelligence?view=azure-dotnet +[docint_nuget_package]: https://www.nuget.org/packages/Azure.AI.DocumentIntelligence [docint_samples]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/README.md -[docint_rest_api]: https://aka.ms/azsdk/formrecognizer/restapi [docint_models]: https://aka.ms/azsdk/formrecognizer/models [docint_errors]: https://aka.ms/azsdk/formrecognizer/errors [docint_build_model]: https://aka.ms/azsdk/formrecognizer/buildmodel -[cognitive_resource]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account +[docint_resource]: https://learn.microsoft.com/azure/ai-services/document-intelligence/how-to-guides/create-document-intelligence-resource +[ai_resource]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account [doc_intelligence_client_class]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/DocumentIntelligenceClient.cs [azure_identity]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity [register_aad_app]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal -[aad_grant_access]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal [custom_subdomain]: https://learn.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain [DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity/README.md -[cognitive_resource_portal]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account [cognitive_resource_cli]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli [regional_endpoints]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-custom-subdomains#is-there-a-list-of-regional-endpoints [azure_cli_endpoint_lookup]: https://learn.microsoft.com/cli/azure/cognitiveservices/account?view=azure-cli-latest#az-cognitiveservices-account-show -[azure_portal_get_endpoint]: https://learn.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#get-the-keys-for-your-resource +[azure_portal_get_endpoint]: https://learn.microsoft.com/azure/ai-services/document-intelligence/how-to-guides/create-document-intelligence-resource#get-endpoint-url-and-keys [di_studio]: https://aka.ms/azsdk/formrecognizer/formrecognizerstudio @@ -643,7 +638,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [azure_cli]: https://learn.microsoft.com/cli/azure [azure_sub]: https://azure.microsoft.com/free/dotnet/ [nuget]: https://www.nuget.org/ -[azure_portal]: https://portal.azure.com [cla]: https://cla.microsoft.com [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AddOnCapabilities.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AddOnCapabilities.md index 32a6b28edef0..27d640acf526 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AddOnCapabilities.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AddOnCapabilities.md @@ -2,15 +2,15 @@ This sample demonstrates how to analyze a document with add-on capabilities. For more information about the supported features, see the [service documentation][docint_addon]. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. When analyzing a document, you can specify a list of optional [analysis features][sdk_docfeature] to enable certain add-on capabilities. Some of the capabilities are free, while others incur additional charges, see [pricing][docint_pricing] for more information. ## Creating a `DocumentIntelligenceClient` -To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AnalyzeWithPrebuiltModel.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AnalyzeWithPrebuiltModel.md index cc612429e9c1..7cdf55a1abfa 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AnalyzeWithPrebuiltModel.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_AnalyzeWithPrebuiltModel.md @@ -2,13 +2,13 @@ This sample demonstrates how to analyze data from certain types of common documents with prebuilt models, using an invoice as an example. For more information about prebuilt models and which types of documents are supported, see the [service documentation][docint_models]. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceClient` -To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; @@ -24,10 +24,7 @@ For simplicity, we are not showing all the fields that the service returns. To s ```C# Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelFromUriAsync Uri uriSource = new Uri(""); - -var options = new AnalyzeDocumentOptions("prebuilt-invoice", uriSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", uriSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildCustomModel.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildCustomModel.md index a60912c5d890..b3dee9c57eae 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildCustomModel.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildCustomModel.md @@ -4,13 +4,13 @@ This sample demonstrates how to build a custom model with your own data. A custo Please note that models can also be created using a graphical user interface such as the [Document Intelligence Studio][di_studio]. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceAdministrationClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildDocumentClassifier.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildDocumentClassifier.md index fdda2a12aa2c..c922722f8817 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildDocumentClassifier.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_BuildDocumentClassifier.md @@ -4,13 +4,13 @@ This sample demonstrates how to build a document classifier with your own data. Please note that document classifiers can also be created using a graphical user interface such as the [Document Intelligence Studio][di_studio]. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceAdministrationClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ClassifyDocument.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ClassifyDocument.md index 414af5e00a95..420c3bec5d4b 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ClassifyDocument.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ClassifyDocument.md @@ -2,13 +2,13 @@ This sample demonstrates how to use document classifiers to accurately detect and identify documents you process within your application. Document classifiers are trained with your own data, so they're tailored to your documents. For more information on how to do the training, see [build a document classifier][build_classifier]. -To get started you'll need a Cognitive Services resource or a Form Recognizer resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceClient` -To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_CopyCustomModel.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_CopyCustomModel.md index ae6c490d6398..d9960fcf8188 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_CopyCustomModel.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_CopyCustomModel.md @@ -2,7 +2,7 @@ This sample demonstrates how to copy a custom model between Document Intelligence resources. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Copy a custom model @@ -16,9 +16,9 @@ For this sample, you will copy a model across Document Intelligence resources. I ## Creating the source and target `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ### Source client @@ -42,7 +42,7 @@ var targetClient = new DocumentIntelligenceAdministrationClient(new Uri(targetEn ### Authorize the copy -Before starting, we need to get a `CopyAuthorization` from the target resource that will give us permission to execute the copy. +Before starting, we need to get a `ModelCopyAuthorization` from the target resource that will give us permission to execute the copy. ```C# Snippet:DocumentIntelligenceSampleGetCopyAuthorization string targetModelId = ""; var authorizeCopyOptions = new AuthorizeModelCopyOptions(targetModelId); diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayout.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayout.md index 18cb60ac98fe..0e8413df9a82 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayout.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayout.md @@ -2,13 +2,13 @@ This sample demonstrates how to extract text, paragraphs, styles, table structures, and selection marks, along with their bounding region coordinates from documents. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceClient` -To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; @@ -22,10 +22,7 @@ To extract the layout from a given file at a URI, use the `AnalyzeDocument` meth ```C# Snippet:DocumentIntelligenceExtractLayoutFromUriAsync Uri uriSource = new Uri(""); - -var options = new AnalyzeDocumentOptions("prebuilt-layout", uriSource); - -Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); +Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", uriSource); AnalyzeResult result = operation.Value; foreach (DocumentPage page in result.Pages) diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayoutAsMarkdown.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayoutAsMarkdown.md index 3794512d7e58..8911a8a2ca95 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayoutAsMarkdown.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ExtractLayoutAsMarkdown.md @@ -2,13 +2,13 @@ This sample demonstrates how to extract text, paragraphs, styles, table structures, and selection marks, along with their bounding region coordinates from documents, presenting the output text in Markdown syntax. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceClient` -To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceClient string endpoint = ""; @@ -18,7 +18,7 @@ var client = new DocumentIntelligenceClient(new Uri(endpoint), credential); ## Extract the layout of a document as Markdown -To extract the layout from a given file at a URI, use the `AnalyzeDocument` method and pass `prebuilt-layout` as the model ID. The output format can be selected with the optional parameter `outputContentFormat`, which we will set to `Markdown` in the sample below. The returned value is an `AnalyzeResult` object containing data about the submitted document. +To extract the layout from a given file at a URI, use the `AnalyzeDocument` method and pass `prebuilt-layout` as the model ID. The output format can be selected with the option `OutputContentFormat`, which we will set to `Markdown` in the sample below. The returned value is an `AnalyzeResult` object containing data about the submitted document. ```C# Snippet:DocumentIntelligenceExtractLayoutAsMarkdownAsync Uri uriSource = new Uri(""); diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_GetAndListOperations.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_GetAndListOperations.md index a17380d415bc..22a8c57f2237 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_GetAndListOperations.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_GetAndListOperations.md @@ -2,13 +2,13 @@ This sample demonstrates how to get and list operations of a Document Intelligence resource. Note that operation information only persists for 24 hours. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceAdministrationClient string endpoint = ""; @@ -18,13 +18,14 @@ var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), cre ## Get and List Document Model Operations -The method `GetOperations` returns a list of `OperationDetails` instances. The instances returned by this method contain general information about the operation, such as its ID, its status, and the `PercentCompleted` property to track progress, but it does not include details about the result or errors that happened during its execution. +The method `GetOperations` returns a list of `DocumentIntelligenceOperationDetails` instances. The instances returned by this method contain general information about the operation, such as its ID, its status, and the `PercentCompleted` property to track progress, but it does not include details about the result or errors that happened during its execution. -The method `GetOperation` can be called to get these extra properties. It returns a single `OperationDetails` instance, including the result of the operation and errors, if any. However, in order to access the `Result` property, you need to cast it to one of its derived types: +The method `GetOperation` can be called to get these extra properties. It returns a single `DocumentIntelligenceOperationDetails` instance, including the result of the operation and errors, if any. However, in order to access the `Result` property, you need to cast it to one of its derived types: - A `DocumentModelBuildOperationDetails` for `BuildDocumentModel` operations. - A `DocumentModelCopyToOperationDetails` for `CopyModelTo` operations. - A `DocumentModelComposeOperationDetails` for `ComposeModel` operations. - A `DocumentClassifierBuildOperationDetails` for `BuildClassifier` operations. +- A `DocumentClassifierCopyTolOperationDetails` for `CopyClassifierTo` operations. Note that operation information only persists for 24 hours. @@ -55,6 +56,10 @@ if (operationDetails.Status == DocumentIntelligenceOperationStatus.Succeeded) case DocumentClassifierBuildOperationDetails classifierOperation: Console.WriteLine($"Classifier ID: {classifierOperation.Result.ClassifierId}"); break; + + case DocumentClassifierCopyToOperationDetails classifierOperation: + Console.WriteLine($"Classifier ID: {classifierOperation.Result.ClassifierId}"); + break; } } else if (operationDetails.Status == DocumentIntelligenceOperationStatus.Failed) diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ManageModels.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ManageModels.md index 591b5381e021..7419c484e37b 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ManageModels.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ManageModels.md @@ -2,13 +2,13 @@ This sample demonstrates how to manage the models stored in your resource. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceAdministrationClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ModelCompose.md b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ModelCompose.md index ec74208f1fad..b4df3aaf37a1 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ModelCompose.md +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/samples/Sample_ModelCompose.md @@ -2,13 +2,13 @@ Model compose allows multiple models to be composed and called with a single model ID. This is useful when you have created different models and want to aggregate a group of them into a single model that could be used to analyze a document. When doing so, you can let the service decide which model more accurately represents the document, instead of manually trying each model against the document. -To get started you'll need a Cognitive Services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. +To get started you'll need an Azure AI services resource or a Document Intelligence resource. See [README][README] for prerequisites and instructions. ## Creating a `DocumentIntelligenceAdministrationClient` -To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll use a Document Intelligence API key credential by creating an `AzureKeyCredential` object that, if needed, will allow you to update the API key without creating a new client. +To create a new `DocumentIntelligenceAdministrationClient` you need the endpoint and credentials from your resource. In the sample below you'll make use of identity-based authentication by creating a `DefaultAzureCredential` object. -You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. +You can set `endpoint` based on an environment variable, a configuration setting, or any way that works for your application. ```C# Snippet:CreateDocumentIntelligenceAdministrationClient string endpoint = ""; diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/DocumentIntelligenceClientOptions.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/DocumentIntelligenceClientOptions.cs new file mode 100644 index 000000000000..ae4f4d90c80e --- /dev/null +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/DocumentIntelligenceClientOptions.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; + +namespace Azure.AI.DocumentIntelligence +{ + [CodeGenModel("AzureAIDocumentIntelligenceClientOptions")] + public partial class DocumentIntelligenceClientOptions + { + // CUSTOM CODE NOTE: overwriting the behavior of the constructor + // to enable logging of the apim-request-id header by default. + + /// Initializes new instance of DocumentIntelligenceClientOptions. + public DocumentIntelligenceClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2024_11_30 => "2024-11-30", + _ => throw new NotSupportedException() + }; + + Diagnostics.LoggedHeaderNames.Add("apim-request-id"); + } + } +} diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/Generated/DocumentIntelligenceClientOptions.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/Generated/DocumentIntelligenceClientOptions.cs index 8f7372727a87..98d466ccc87c 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/Generated/DocumentIntelligenceClientOptions.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/Generated/DocumentIntelligenceClientOptions.cs @@ -23,15 +23,5 @@ public enum ServiceVersion } internal string Version { get; } - - /// Initializes new instance of DocumentIntelligenceClientOptions. - public DocumentIntelligenceClientOptions(ServiceVersion version = LatestVersion) - { - Version = version switch - { - ServiceVersion.V2024_11_30 => "2024-11-30", - _ => throw new NotSupportedException() - }; - } } } diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/GeneratorStubs/PublicTypes.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/GeneratorStubs/PublicTypes.cs index 1fd50fb50b6b..80cb6a8933ba 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/GeneratorStubs/PublicTypes.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/src/GeneratorStubs/PublicTypes.cs @@ -20,9 +20,6 @@ public partial class AnalyzeResult public readonly partial struct BoundingRegion { } - [CodeGenModel("AzureAIDocumentIntelligenceClientOptions")] - public partial class DocumentIntelligenceClientOptions { } - public readonly partial struct DocumentSpan { } } diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/SampleAnalyzeWithPrebuiltModelFromBytes.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromBytes.cs similarity index 96% rename from sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/SampleAnalyzeWithPrebuiltModelFromBytes.cs rename to sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromBytes.cs index 87a9bc74ab78..09243ab4c3ea 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/SampleAnalyzeWithPrebuiltModelFromBytes.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromBytes.cs @@ -26,10 +26,8 @@ public async Task AnalyzeWithPrebuiltModelFromBytesAsync() #endif byte[] fileBytes = File.ReadAllBytes(filePath); - var bytesSource = BinaryData.FromBytes(fileBytes); - var options = new AnalyzeDocumentOptions("prebuilt-invoice", bytesSource); - - Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); + BinaryData bytesSource = BinaryData.FromBytes(fileBytes); + Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", bytesSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromUri.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromUri.cs index f4dfcef54167..da1ce0c4edd6 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromUri.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_AnalyzeWithPrebuiltModelFromUri.cs @@ -23,10 +23,7 @@ public async Task AnalyzeWithPrebuiltModelFromUriAsync() #else Uri uriSource = DocumentIntelligenceTestEnvironment.CreateUri("Form_1.jpg"); #endif - - var options = new AnalyzeDocumentOptions("prebuilt-invoice", uriSource); - - Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); + Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-invoice", uriSource); AnalyzeResult result = operation.Value; // To see the list of all the supported fields returned by service and its corresponding types for the diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_ExtractLayoutFromUriAsync.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_ExtractLayoutFromUriAsync.cs index 9a4923aca999..ef4d5222feed 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_ExtractLayoutFromUriAsync.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_ExtractLayoutFromUriAsync.cs @@ -23,10 +23,7 @@ public async Task ExtractLayoutFromUriAsync() #else Uri uriSource = DocumentIntelligenceTestEnvironment.CreateUri("Form_1.jpg"); #endif - - var options = new AnalyzeDocumentOptions("prebuilt-layout", uriSource); - - Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, options); + Operation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", uriSource); AnalyzeResult result = operation.Value; foreach (DocumentPage page in result.Pages) diff --git a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_GetAndListOperationsAsync.cs b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_GetAndListOperationsAsync.cs index 834e04a95f55..19306bbe3f7d 100644 --- a/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_GetAndListOperationsAsync.cs +++ b/sdk/documentintelligence/Azure.AI.DocumentIntelligence/tests/samples/Sample_GetAndListOperationsAsync.cs @@ -54,6 +54,10 @@ public async Task GetAndListOperationsAsync() case DocumentClassifierBuildOperationDetails classifierOperation: Console.WriteLine($"Classifier ID: {classifierOperation.Result.ClassifierId}"); break; + + case DocumentClassifierCopyToOperationDetails classifierOperation: + Console.WriteLine($"Classifier ID: {classifierOperation.Result.ClassifierId}"); + break; } } else if (operationDetails.Status == DocumentIntelligenceOperationStatus.Failed)