Skip to content

Commit 897f81d

Browse files
Yalin Licperaltah
andauthored
Regenerate DI for API 2024-11-30 (Azure#38529)
* Regen * Remove generated samples and tests * Customize on batch analyze operation * Create sample_analyze_batch_documents.py * Regen * Align new names in _patch.py * Regen * Update batch analyze samples * Default content-type when analyze request is a stream * Fix typo * Update docstring in patch * Update README.md * Fix mypy pylint * Update MIGRATION_GUIDE.md * Update CHANGELOG.md * body rename * black * update emitter version * fix changelog entry * fix content type patch * fix content type logic + some patch body renames * test fixes * rename body params * regen with latest python emitter * changelog update * more renaming fixes * required body fix * fix tests * update docs * test fix * update samples * fix link * fix async patch * pylint * formatting * long line * update tests * revert content type change * content type wip * test updates * fix tests * fix tests * fix assert * update tests * update batch tests * update assets.json * skip assert * update assert * revert recorded_variables change * patch fix * pylint * spelling * skip assert * pylint * set bodiless matcher * update recordings * skip test --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent 7674316 commit 897f81d

File tree

81 files changed

+2619
-1870
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2619
-1870
lines changed

sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
# Release History
22

3-
## 1.0.0b5 (Unreleased)
3+
## 1.0.0 (Unreleased)
44

55
### Features Added
66

7+
- Added support for the Analyze Batch Documents API:
8+
- Added operations `delete_analyze_batch_result()`, `get_analyze_batch_result()` and `list_analyze_batch_results()` to `DocumentIntelligenceClient`.
9+
- Added support for the Analyze Documents API:
10+
- Added operations `delete_analyze_result()` to `DocumentIntelligenceClient`.
11+
712
### Breaking Changes
813

14+
- Renamed request body parameters on all methods to `body`.
15+
- Renamed operation `get_resource_info()` to `get_resource_details()`.
16+
- Renamed model `ContentFormat` to `DocumentContentFormat`.
17+
- Renamed model `AnalyzeBatchResultOperation` to `AnalyzeBatchOperation`.
18+
- Renamed model `CopyAuthorization` to `ModelCopyAuthorization`.
19+
- Renamed model `Document` to `AnalyzedDocument`.
20+
- Renamed model `Error` to `DocumentIntelligenceError`.
21+
- Renamed model `ErrorResponse` to `DocumentIntelligenceErrorResponse`.
22+
- Renamed model `InnerError` to `DocumentIntelligenceInnerError`.
23+
- Renamed model `OperationDetails` to `DocumentIntelligenceOperationDetails`.
24+
- Renamed model `OperationStatus` to `DocumentIntelligenceOperationStatus`.
25+
- Renamed model `ResourceDetails` to `DocumentIntelligenceResourceDetails`.
26+
- Renamed model `Warning` to `DocumentIntelligenceWarning`.
27+
- Renamed property `items_property` in model `DocumentFieldSchema` to `items_schema`.
28+
- Renamed enum `FontStyle` to `DocumentFontStyle`.
29+
- Renamed enum `FontWeight` to `DocumentFontWeight`.
30+
- Removed model `AnalyzeResultOperation`.
31+
- Removed `GENERATIVE ` in enum `DocumentBuildMode`.
32+
933
### Bugs Fixed
1034

1135
### Other Changes
1236

37+
- No need to pass `content-type` when analyze_request is a stream in `begin_analyze_document()` and `begin_classify_document()`.
38+
1339
## 1.0.0b4 (2024-09-05)
1440

1541
### Features Added
42+
1643
- Added support for the Analyze Batch Documents API:
17-
- Added LRO operation `begin_analyze_batch_documents()` to `DocumentIntelligenceClient`.
18-
- Added models `AnalyzeBatchDocumentsRequest`, `AnalyzeBatchResult` and `AnalyzeBatchOperationDetail`.
44+
- Added LRO operation `begin_analyze_batch_documents()` to `DocumentIntelligenceClient`.
45+
- Added models `AnalyzeBatchDocumentsRequest`, `AnalyzeBatchResult` and `AnalyzeBatchOperationDetail`.
1946
- Added support for different kinds of output in the Analyze Document API:
20-
- Added operations `get_analyze_result_figure()` and `get_analyze_result_pdf()` to `DocumentIntelligenceClient`.
21-
- Added optional kwarg `output` to LRO operation `begin_analyze_document()` overloads in `DocumentIntelligenceClient`.
22-
- Added enum `AnalyzeOutputOption` to specify output kind, either `pdf` or `figures`.
23-
- Added property `id` to model `DocumentFigure`.
47+
- Added operations `get_analyze_result_figure()` and `get_analyze_result_pdf()` to `DocumentIntelligenceClient`.
48+
- Added optional kwarg `output` to LRO operation `begin_analyze_document()` overloads in `DocumentIntelligenceClient`.
49+
- Added enum `AnalyzeOutputOption` to specify output kind, either `pdf` or `figures`.
50+
- Added property `id` to model `DocumentFigure`.
2451
- Added support for the Copy Classifier API:
25-
- Added operations `authorize_classifier_copy()` and `begin_copy_classifier_to()` to `DocumentIntelligenceAdministrationClient`.
26-
- Added models `AuthorizeClassifierCopyRequest` and `ClassifierCopyAuthorization`.
52+
- Added operations `authorize_classifier_copy()` and `begin_copy_classifier_to()` to `DocumentIntelligenceAdministrationClient`.
53+
- Added models `AuthorizeClassifierCopyRequest` and `ClassifierCopyAuthorization`.
2754
- Added optional kwarg `pages` to LRO operation `begin_classify_document()` overloads in `DocumentIntelligenceClient`.
2855
- Added new kind `GENERATIVE` to enum `DocumentBuildMode`.
2956
- Added property `warnings` to model `AnalyzeResult`.
@@ -35,24 +62,27 @@
3562
- Added support for getting `operation_id` via `details` property in the new return types `AnalyzeDocumentLROPoller` and `AsyncAnalyzeDocumentLROPoller` in operation `begin_analyze_document()`.
3663

3764
### Breaking Changes
65+
3866
- Removed support for extracting lists from analyzed documents:
39-
- Removed models `DocumentList` and `DocumentListItem`.
40-
- Removed property `lists` from model `AnalyzeResult`.
67+
- Removed models `DocumentList` and `DocumentListItem`.
68+
- Removed property `lists` from model `AnalyzeResult`.
4169
- Changes to the Compose Document API:
42-
- Removed model `ComponentDocumentModelDetails`.
43-
- Removed property `component_models` from model `ComposeDocumentModelRequest`.
44-
- `ComposeDocumentModelRequest` now requires a dictionary of `DocumentTypeDetails` instances and a classifier ID to be constructed.
70+
- Removed model `ComponentDocumentModelDetails`.
71+
- Removed property `component_models` from model `ComposeDocumentModelRequest`.
72+
- `ComposeDocumentModelRequest` now requires a dictionary of `DocumentTypeDetails` instances and a classifier ID to be constructed.
4573
- Removed model `QuotaDetails`.
4674
- Removed property `custom_neural_document_model_builds` from model `ResourceDetails`.
4775
- Changed the _required_ property `field_schema` from `DocumentTypeDetails` to be _optional_.
4876

4977
### Other Changes
78+
5079
- Changed the default service API version to `2024-07-31-preview`.
51-
- Improved performance by about `1.5X` faster when deserializing `JSON` to an `AnalyzeResult` object compared to last version `1.0.0b3`.
80+
- Improved performance by about `1.5X` faster when deserializing `JSON` to an `AnalyzeResult` object compared to last version `1.0.0b3`.
5281

5382
## 1.0.0b3 (2024-04-09)
5483

5584
### Other Changes
85+
5686
- Changed the default polling interval from 5s to 1s.
5787

5888
## 1.0.0b2 (2024-03-07)

sdk/documentintelligence/azure-ai-documentintelligence/MIGRATION_GUIDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ There are many benefits to using the new design of the `azure-ai-documentintelli
2727

2828
Supports output with Markdown content format along with the default plain _text_. For now, this is only supported for "prebuilt-layout". Markdown content format is deemed a more friendly format for LLM consumption in a chat or automation use scenario. Custom models should continue to use the default "text" content format for generating .ocr.json results.
2929

30-
Service follows the GFM spec ([GitHub Flavored Markdown](https://github.github.com/gfm/)) for the Markdown format. This SDK introduces a new enum _ContentFormat_ with value "text" or "markdown" to indicate the result content format.
30+
Service follows the GFM spec ([GitHub Flavored Markdown](https://github.github.com/gfm/)) for the Markdown format. This SDK introduces a new enum _DocumentContentFormat_ with value "text" or "markdown" to indicate the result content format.
3131

3232
```python
3333
from azure.core.credentials import AzureKeyCredential
3434
from azure.ai.documentintelligence import DocumentIntelligenceClient
35-
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, ContentFormat
35+
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, DocumentContentFormat
3636

3737
endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"]
3838
key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
3939
url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf"
4040

4141
client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))
4242
poller = client.begin_analyze_document(
43-
"prebuilt-layout", AnalyzeDocumentRequest(url_source=url), output_content_format=ContentFormat.MARKDOWN
43+
"prebuilt-layout", AnalyzeDocumentRequest(url_source=url), output_content_format=DocumentContentFormat.MARKDOWN
4444
)
4545
result = poller.result()
4646
```

sdk/documentintelligence/azure-ai-documentintelligence/README.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ python -m pip install azure-ai-documentintelligence
3030

3131
This table shows the relationship between SDK versions and supported API service versions:
3232

33-
|SDK version|Supported API service version|
34-
|-|-|
35-
|1.0.0b1 | 2023-10-31-preview|
36-
|1.0.0b2 | 2024-02-29-preview|
33+
| SDK version | Supported API service version |
34+
| ----------- | ----------------------------- |
35+
| 1.0.0 | 2024-11-30 |
3736

3837
Older API versions are supported in `azure-ai-formrecognizer`, please see the [Migration Guide][migration-guide] for detailed instructions on how to update application.
3938

@@ -47,10 +46,10 @@ Older API versions are supported in `azure-ai-formrecognizer`, please see the [M
4746

4847
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/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-the-client-with-an-azure-active-directory-credential).
4948

50-
You can create either resource using:
49+
You can create either resource using:
5150

52-
* Option 1: [Azure Portal][cognitive_resource_portal].
53-
* Option 2: [Azure CLI][cognitive_resource_cli].
51+
- Option 1: [Azure Portal][cognitive_resource_portal].
52+
- Option 2: [Azure CLI][cognitive_resource_cli].
5453

5554
Below is an example of how you can create a Document Intelligence resource using the CLI:
5655

@@ -132,9 +131,11 @@ name for your resource in order to use this type of authentication.
132131
To use the [DefaultAzureCredential][default_azure_credential] type shown below, or other credential types provided
133132
with the Azure SDK, please install the `azure-identity` package:
134133

135-
```pip install azure-identity```
134+
```
135+
pip install azure-identity
136+
```
136137

137-
You will also need to [register a new AAD application and grant access][register_aad_app] to Document Intelligence by assigning the `"Cognitive Services User"` role to your service principal.
138+
You will also need to [register a new AAD application and grant access][register_aad_app] to Document Intelligence by assigning the [Cognitive Services Data Reader][entra_auth_role] role to your service principal.
138139

139140
Once completed, set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
140141
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
@@ -157,8 +158,8 @@ document_intelligence_client = DocumentIntelligenceClient(endpoint, credential)
157158
### DocumentIntelligenceClient
158159

159160
`DocumentIntelligenceClient` provides operations for analyzing input documents using prebuilt and custom models through the `begin_analyze_document` API.
160-
Use the `model_id` parameter to select the type of model for analysis. See a full list of supported models [here][di-models].
161-
The `DocumentIntelligenceClient` also provides operations for classifying documents through the `begin_classify_document` API.
161+
Use the `model_id` parameter to select the type of model for analysis. See a full list of supported models [here][di-models].
162+
The `DocumentIntelligenceClient` also provides operations for classifying documents through the `begin_classify_document` API.
162163
Custom classification models can classify each page in an input file to identify the document(s) within and can also identify multiple documents or multiple instances of a single document within an input file.
163164

164165
Sample code snippets are provided to illustrate using a DocumentIntelligenceClient [here](#examples "Examples").
@@ -194,16 +195,16 @@ Sample code snippets are provided to illustrate using long-running operations [b
194195

195196
The following section provides several code snippets covering some of the most common Document Intelligence tasks, including:
196197

197-
* [Extract Layout](#extract-layout "Extract Layout")
198-
* [Extract Figures from Documents](#extract-figures-from-documents "Extract Figures from Documents")
199-
* [Analyze Documents Result in PDF](#analyze-documents-result-in-pdf "Analyze Documents Result in PDF")
200-
* [Using the General Document Model](#using-the-general-document-model "Using the General Document Model")
201-
* [Using Prebuilt Models](#using-prebuilt-models "Using Prebuilt Models")
202-
* [Build a Custom Model](#build-a-custom-model "Build a custom model")
203-
* [Analyze Documents Using a Custom Model](#analyze-documents-using-a-custom-model "Analyze Documents Using a Custom Model")
204-
* [Manage Your Models](#manage-your-models "Manage Your Models")
205-
* [Add-on Capabilities](#add-on-capabilities "Add-on Capabilities")
206-
* [Get Raw JSON Result](#get-raw-json-result "Get Raw JSON Result")
198+
- [Extract Layout](#extract-layout "Extract Layout")
199+
- [Extract Figures from Documents](#extract-figures-from-documents "Extract Figures from Documents")
200+
- [Analyze Documents Result in PDF](#analyze-documents-result-in-pdf "Analyze Documents Result in PDF")
201+
- [Using the General Document Model](#using-the-general-document-model "Using the General Document Model")
202+
- [Using Prebuilt Models](#using-prebuilt-models "Using Prebuilt Models")
203+
- [Build a Custom Model](#build-a-custom-model "Build a custom model")
204+
- [Analyze Documents Using a Custom Model](#analyze-documents-using-a-custom-model "Analyze Documents Using a Custom Model")
205+
- [Manage Your Models](#manage-your-models "Manage Your Models")
206+
- [Add-on Capabilities](#add-on-capabilities "Add-on Capabilities")
207+
- [Get Raw JSON Result](#get-raw-json-result "Get Raw JSON Result")
207208

208209
### Extract Layout
209210

@@ -233,7 +234,7 @@ key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
233234
document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))
234235
with open(path_to_sample_documents, "rb") as f:
235236
poller = document_intelligence_client.begin_analyze_document(
236-
"prebuilt-layout", analyze_request=f, content_type="application/octet-stream"
237+
"prebuilt-layout", body=f
237238
)
238239
result: AnalyzeResult = poller.result()
239240

@@ -325,9 +326,8 @@ document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, cre
325326
with open(path_to_sample_documents, "rb") as f:
326327
poller = document_intelligence_client.begin_analyze_document(
327328
"prebuilt-layout",
328-
analyze_request=f,
329+
body=f,
329330
output=[AnalyzeOutputOption.FIGURES],
330-
content_type="application/octet-stream",
331331
)
332332
result: AnalyzeResult = poller.result()
333333
operation_id = poller.details["operation_id"]
@@ -367,9 +367,8 @@ document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, cre
367367
with open(path_to_sample_documents, "rb") as f:
368368
poller = document_intelligence_client.begin_analyze_document(
369369
"prebuilt-read",
370-
analyze_request=f,
370+
body=f,
371371
output=[AnalyzeOutputOption.PDF],
372-
content_type="application/octet-stream",
373372
)
374373
result: AnalyzeResult = poller.result()
375374
operation_id = poller.details["operation_id"]
@@ -418,9 +417,8 @@ document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, cre
418417
with open(path_to_sample_documents, "rb") as f:
419418
poller = document_intelligence_client.begin_analyze_document(
420419
"prebuilt-layout",
421-
analyze_request=f,
420+
body=f,
422421
features=[DocumentAnalysisFeature.KEY_VALUE_PAIRS],
423-
content_type="application/octet-stream",
424422
)
425423
result: AnalyzeResult = poller.result()
426424

@@ -513,7 +511,7 @@ key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"]
513511
document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))
514512
with open(path_to_sample_documents, "rb") as f:
515513
poller = document_intelligence_client.begin_analyze_document(
516-
"prebuilt-receipt", analyze_request=f, locale="en-US", content_type="application/octet-stream"
514+
"prebuilt-receipt", body=f, locale="en-US"
517515
)
518516
receipts: AnalyzeResult = poller.result()
519517

@@ -668,7 +666,7 @@ document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, cre
668666
# Make sure your document's type is included in the list of document types the custom model can analyze
669667
with open(path_to_sample_documents, "rb") as f:
670668
poller = document_intelligence_client.begin_analyze_document(
671-
model_id=model_id, analyze_request=f, content_type="application/octet-stream"
669+
model_id=model_id, body=f
672670
)
673671
result: AnalyzeResult = poller.result()
674672

@@ -827,10 +825,10 @@ if model.doc_types:
827825

828826
<!-- END SNIPPET -->
829827

830-
<!-- SNIPPET:sample_manage_models.get_resource_info -->
828+
<!-- SNIPPET:sample_manage_models.get_resource_details -->
831829

832830
```python
833-
account_details = document_intelligence_admin_client.get_resource_info()
831+
account_details = document_intelligence_admin_client.get_resource_details()
834832
print(
835833
f"Our resource has {account_details.custom_document_models.count} custom models, "
836834
f"and we can have at most {account_details.custom_document_models.limit} custom models"
@@ -885,9 +883,11 @@ except ResourceNotFoundError:
885883
<!-- END SNIPPET -->
886884

887885
### Add-on Capabilities
886+
888887
Document Intelligence supports more sophisticated analysis capabilities. These optional features can be enabled and disabled depending on the scenario of the document extraction.
889888

890889
The following add-on capabilities are available in this SDK:
890+
891891
- [barcode/QR code][addon_barcodes_sample]
892892
- [formula][addon_formulas_sample]
893893
- [font/style][addon_fonts_sample]
@@ -900,6 +900,7 @@ Note that some add-on capabilities will incur additional charges. See pricing: h
900900
### Get Raw JSON Result
901901

902902
Can get the HTTP response by passing parameter `raw_response_hook` to any client method.
903+
903904
<!-- SNIPPET:sample_get_raw_response.raw_response_hook -->
904905

905906
```python
@@ -918,7 +919,7 @@ def callback(response):
918919
responses["status_code"] = response.http_response.status_code
919920
responses["response_body"] = response.http_response.json()
920921

921-
client.get_resource_info(raw_response_hook=callback)
922+
client.get_resource_details(raw_response_hook=callback)
922923

923924
print(f"Response status code is: {responses["status_code"]}")
924925
response_body = responses["response_body"]
@@ -964,7 +965,6 @@ print(
964965

965966
<!-- END SNIPPET -->
966967

967-
968968
## Troubleshooting
969969

970970
### General
@@ -1000,7 +1000,6 @@ See the [Sample README][sample_readme] for several code snippets illustrating co
10001000

10011001
For more extensive documentation on Azure AI Document Intelligence, see the [Document Intelligence documentation][python-di-product-docs] on docs.microsoft.com.
10021002

1003-
10041003
## Contributing
10051004

10061005
This project welcomes contributions and suggestions. Most contributions require
@@ -1019,6 +1018,7 @@ see the Code of Conduct FAQ or contact [email protected] with any
10191018
additional questions or comments.
10201019

10211020
<!-- LINKS -->
1021+
10221022
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
10231023
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
10241024
[azure_sub]: https://azure.microsoft.com/free/
@@ -1045,6 +1045,7 @@ additional questions or comments.
10451045
[azure_portal_get_endpoint]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#get-the-keys-for-your-resource
10461046
[cognitive_authentication_api_key]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows#get-the-keys-for-your-resource
10471047
[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
1048+
[entra_auth_role]: https://learn.microsoft.com/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-data-reader
10481049
[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain
10491050
[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
10501051
[sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/sdk/azure-sdk-logging

sdk/documentintelligence/azure-ai-documentintelligence/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/documentintelligence/azure-ai-documentintelligence",
5-
"Tag": "python/documentintelligence/azure-ai-documentintelligence_a520415df9"
5+
"Tag": "python/documentintelligence/azure-ai-documentintelligence_faf458f6e7"
66
}

0 commit comments

Comments
 (0)