Skip to content

Commit 5add947

Browse files
[formrecognizer] GA work (Azure#25809)
* [formrecognizer] Preview cleanup (Azure#25711) * remove preview refs in samples * remove preview refs in migration guide and readme * [formrecognizer] Regenerate with new swagger (Azure#25710) * regenerate with new swagger * update versions and refs to GA version * fix import * fix dmac tests * update api version refs * update swagger readme * update dmac operations, tests, & recordings * add copy recordings * remove kind from DocumentPage * update generated models and operations refs * update DAC prebuilt tests * update dac custom model recordings * update general document recordings * update layout recordings * update prebuilt read recordings * update prebuilts recordings * update dmac mgmt recordings * update dmac operation refs * update get children recordings * regenerate with latest swagger * update dmac training recordings * dac from url method, check url is str * enable bad endpoint tests * pylint and changelog updates * shorten dmac lines * api version changelog entry * regenerate with python 3 only * update swagger readme * added autorest.python version used to regenerate in example command
1 parent 9299654 commit 5add947

File tree

299 files changed

+210061
-140876
lines changed

Some content is hidden

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

299 files changed

+210061
-140876
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Features Added
66

77
### Breaking Changes
8+
- This library will default to service API version `2022-08-31` going forward.
9+
- Removed `kind` property on `DocumentPage`.
810

911
### Bugs Fixed
1012

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Guide for migrating azure-ai-formrecognizer to version 3.2.x from versions 3.1.x and below
22

3-
This guide is intended to assist in the migration to `azure-ai-formrecognizer (3.2.x)` from versions `3.1.x` and below. It will focus on side-by-side comparisons for similar operations between versions. Please note that version `3.2.0b6` will be used for comparison with `3.1.2`.
3+
This guide is intended to assist in the migration to `azure-ai-formrecognizer (3.2.x)` from versions `3.1.x` and below. It will focus on side-by-side comparisons for similar operations between versions. Please note that version `3.2.0` will be used for comparison with `3.1.2`.
44

5-
> NOTE: Please read the [CHANGELOG][changelog] to see important changes that have occurred since version `3.2.0b6` of the SDK.
5+
> NOTE: Please read the [CHANGELOG][changelog] to see important changes that have occurred since version `3.2.0` of the SDK.
66
77
Familiarity with `azure-ai-formrecognizer (3.1.x and below)` package is assumed. For those new to the Azure Form Recognizer client library for Python please refer to the [README][readme] rather than this guide.
88

@@ -21,7 +21,7 @@ Familiarity with `azure-ai-formrecognizer (3.1.x and below)` package is assumed.
2121

2222
A natural question to ask when considering whether to adopt a new version of the library is what the benefits of doing so would be. As Azure Form Recognizer has matured and been embraced by a more diverse group of developers, we have been focused on learning the patterns and practices to best support developer productivity and add value to our customers.
2323

24-
There are many benefits to using the new design of the `azure-ai-formrecognizer (3.2.x)` library. This new version of the library introduces two new clients `DocumentAnalysisClient` and the `DocumentModelAdministrationClient` with unified methods for analyzing documents and provides support for the new features added by the service in API version `2022-06-30-preview` and later.
24+
There are many benefits to using the new design of the `azure-ai-formrecognizer (3.2.x)` library. This new version of the library introduces two new clients `DocumentAnalysisClient` and the `DocumentModelAdministrationClient` with unified methods for analyzing documents and provides support for the new features added by the service in API version `2022-08-31` and later.
2525

2626
New features provided by the `DocumentAnalysisClient` include:
2727
- One consolidated method for analyzing document layout, a prebuilt general document model type, a prebuilt read model to get text detection and detected languages, along with more new prebuilt models that can be seen [here][fr-models].
@@ -40,7 +40,7 @@ The table below describes the relationship of each client and its supported API
4040

4141
|API version|Supported clients
4242
|-|-
43-
|2022-06-30-preview | DocumentAnalysisClient and DocumentModelAdministrationClient
43+
|2022-08-31 | DocumentAnalysisClient and DocumentModelAdministrationClient
4444
|2.1 | FormRecognizerClient and FormTrainingClient
4545
|2.0 | FormRecognizerClient and FormTrainingClient
4646

@@ -61,7 +61,7 @@ Some terminology has changed to reflect the enhanced capabilities of the newest
6161

6262
We continue to support API key and AAD authentication methods when creating the clients. Below are the differences between the two versions:
6363

64-
- In `3.2.x`, we have added `DocumentAnalysisClient` and `DocumentModelAdministrationClient` which support API version `2022-06-30-preview` and later.
64+
- In `3.2.x`, we have added `DocumentAnalysisClient` and `DocumentModelAdministrationClient` which support API version `2022-08-31` and later.
6565
- `FormRecognizerClient` and `FormTrainingClient` will continue to work targeting API versions `2.1` and `2.0`.
6666
- In `DocumentAnalysisClient` all prebuilt model methods along with custom model, layout, and a prebuilt general document analysis model are unified into two methods called
6767
`begin_analyze_document` and `begin_analyze_document_from_url`.
@@ -109,7 +109,7 @@ Differences between the versions:
109109
- In the new version of the library, the functionality of `begin_recognize_content` has been added as a prebuilt model and can be called in library version `azure-ai-formrecognizer (3.2.x)` with `begin_analyze_document` by passing in the `prebuilt-layout` model ID. Similarly, to get general document information, such as key-value pairs and text layout, the `prebuilt-document` model ID can be used with `begin_analyze_document`. Additionally, passing in the `prebuilt-read` model was added to read information about pages and detected languages.
110110
- When calling `begin_analyze_document` and `begin_analyze_document_from_url` the returned type is an `AnalyzeResult` object, while the various methods used with `FormRecognizerClient` return a list of `RecognizedForm`.
111111
- The `pages` keyword argument is a string with library version `azure-ai-formrecognizer (3.2.x)`. In `azure-ai-formrecognizer (3.1.x)`, `pages` was a list of strings.
112-
- The `include_field_elements` keyword argument is not supported with the `DocumentAnalysisClient`, text details are automatically included with API version `2022-06-30-preview` and later.
112+
- The `include_field_elements` keyword argument is not supported with the `DocumentAnalysisClient`, text details are automatically included with API version `2022-08-31` and later.
113113
- The `reading_order` keyword argument does not exist on `begin_analyze_document` and `begin_analyze_document_from_url`. The service uses `natural` reading order to return data.
114114

115115
Analyzing prebuilt models like business cards, identity documents, invoices, and receipts with `3.1.x`:
@@ -480,7 +480,7 @@ print("----------------------------------------")
480480
Differences between the versions:
481481
- Analyzing a custom model with `DocumentAnalysisClient` uses the general `begin_analyze_document` and `begin_analyze_document_from_url` methods.
482482
- In order to analyze a custom model with `FormRecognizerClient` the `begin_recognize_custom_models` and its corresponding URL methods are used.
483-
- The `include_field_elements` keyword argument is not supported with the `DocumentAnalysisClient`, text details are automatically included with API version `2022-06-30-preview` and later.
483+
- The `include_field_elements` keyword argument is not supported with the `DocumentAnalysisClient`, text details are automatically included with API version `2022-08-31` and later.
484484

485485
Analyze custom document with `3.1.x`:
486486
```python
@@ -654,7 +654,7 @@ for name, doc_type in model.doc_types.items():
654654
### Managing models
655655

656656
Differences between the versions:
657-
- When using API version `2022-06-30-preview` and later models no longer include submodels, instead a model can analyze different document types.
657+
- When using API version `2022-08-31` and later models no longer include submodels, instead a model can analyze different document types.
658658
- When building, composing, or copying models users can now assign their own model IDs and specify a description.
659659
- In version `3.2.x` of the library, only models that build successfully can be retrieved from the get and list model calls. Unsuccessful model operations can be viewed with the get and list operation methods (note that document model operation data persists for only 24 hours). In version `3.1.x` of the library, models that had not succeeded were still created, had to be deleted by the user, and were returned in the list models response.
660660

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ Install the Azure Form Recognizer client library for Python with [pip][pip]:
2828
pip install azure-ai-formrecognizer --pre
2929
```
3030

31-
> Note: This version of the client library defaults to the `2022-06-30-preview` version of the service.
31+
> Note: This version of the client library defaults to the `2022-08-31` version of the service.
3232
3333
This table shows the relationship between SDK versions and supported API versions of the service:
3434

3535
|SDK version|Supported API version of service
3636
|-|-
37-
|3.2.0b6 - Latest beta release | 2.0, 2.1, 2022-06-30-preview
38-
|3.1.X - Latest GA release| 2.0, 2.1 (default)
37+
|3.2.0 - Latest GA release | 2.0, 2.1, 2022-08-31
38+
|3.1.X| 2.0, 2.1 (default)
3939
|3.0.0| 2.0
4040

4141
> Note: Starting with version `3.2.X`, a new set of clients were introduced to leverage the newest features
@@ -45,7 +45,7 @@ This table shows the relationship between SDK versions and supported API version
4545
4646
|API version|Supported clients
4747
|-|-
48-
|2022-06-30-preview | DocumentAnalysisClient and DocumentModelAdministrationClient
48+
|2022-08-31 | DocumentAnalysisClient and DocumentModelAdministrationClient
4949
|2.1 | FormRecognizerClient and FormTrainingClient
5050
|2.0 | FormRecognizerClient and FormTrainingClient
5151

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_api_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DocumentAnalysisApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
1111
"""Form Recognizer API versions supported by DocumentAnalysisClient and DocumentModelAdministrationClient."""
1212

1313
#: This is the default version
14-
V2022_06_30_PREVIEW = "2022-06-30-preview"
14+
V2022_08_31 = "2022-08-31"
1515

1616

1717
class FormRecognizerApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_document_analysis_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DocumentAnalysisClient(FormRecognizerClientBase):
5858
"""
5959

6060
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None:
61-
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_06_30_PREVIEW)
61+
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_08_31)
6262
super().__init__(
6363
endpoint=endpoint, credential=credential, api_version=api_version, client_kind="document", **kwargs
6464
)
@@ -157,6 +157,11 @@ def begin_analyze_document_from_url(
157157
if not model_id:
158158
raise ValueError("model_id cannot be None or empty.")
159159

160+
if not isinstance(document_url, str):
161+
raise ValueError(
162+
"'document_url' needs to be of type 'str'."
163+
"Please see `begin_analyze_document()` to pass a byte stream.")
164+
160165
cls = kwargs.pop("cls", self._analyze_document_callback)
161166
continuation_token = kwargs.pop("continuation_token", None)
162167

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_document_model_administration_client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class DocumentModelAdministrationClient(FormRecognizerClientBase):
8080
"""
8181

8282
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, TokenCredential], **kwargs: Any) -> None:
83-
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_06_30_PREVIEW)
83+
api_version = kwargs.pop("api_version", DocumentAnalysisApiVersion.V2022_08_31)
8484
super().__init__(
8585
endpoint=endpoint, credential=credential, api_version=api_version, client_kind="document", **kwargs
8686
)
@@ -131,8 +131,8 @@ def begin_build_model(
131131
"""
132132

133133
def callback(raw_response, _, headers): # pylint: disable=unused-argument
134-
op_response = self._deserialize(self._generated_models.GetOperationResponse, raw_response)
135-
model_info = self._deserialize(self._generated_models.ModelInfo, op_response.result)
134+
op_response = self._deserialize(self._generated_models.DocumentModelBuildOperationDetails, raw_response)
135+
model_info = self._deserialize(self._generated_models.DocumentModelDetails, op_response.result)
136136
return DocumentModelDetails._from_generated(model_info)
137137

138138
description = kwargs.pop("description", None)
@@ -199,8 +199,8 @@ def begin_compose_model(
199199
"""
200200

201201
def _compose_callback(raw_response, _, headers): # pylint: disable=unused-argument
202-
op_response = self._deserialize(self._generated_models.GetOperationResponse, raw_response)
203-
model_info = self._deserialize(self._generated_models.ModelInfo, op_response.result)
202+
op_response = self._deserialize(self._generated_models.DocumentModelComposeOperationDetails, raw_response)
203+
model_info = self._deserialize(self._generated_models.DocumentModelDetails, op_response.result)
204204
return DocumentModelDetails._from_generated(model_info)
205205

206206
model_id = kwargs.pop("model_id", None)
@@ -218,7 +218,8 @@ def _compose_callback(raw_response, _, headers): # pylint: disable=unused-argum
218218
description=description,
219219
tags=tags,
220220
component_models=[
221-
self._generated_models.ComponentModelInfo(model_id=model_id) for model_id in component_model_ids
221+
self._generated_models.ComponentDocumentModelDetails(model_id=model_id)
222+
for model_id in component_model_ids
222223
]
223224
if component_model_ids
224225
else [],
@@ -298,8 +299,8 @@ def begin_copy_model_to(
298299
"""
299300

300301
def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument
301-
op_response = self._deserialize(self._generated_models.GetOperationResponse, raw_response)
302-
model_info = self._deserialize(self._generated_models.ModelInfo, op_response.result)
302+
op_response = self._deserialize(self._generated_models.DocumentModelCopyToOperationDetails, raw_response)
303+
model_info = self._deserialize(self._generated_models.DocumentModelDetails, op_response.result)
303304
return DocumentModelDetails._from_generated(model_info)
304305

305306
if not model_id:
@@ -350,7 +351,7 @@ def delete_model(self, model_id: str, **kwargs: Any) -> None:
350351
if not model_id:
351352
raise ValueError("model_id cannot be None or empty.")
352353

353-
return self._client.delete_model(model_id=model_id, **kwargs)
354+
return self._client.delete_document_model(model_id=model_id, **kwargs)
354355

355356
@distributed_trace
356357
def list_models(self, **kwargs: Any) -> ItemPaged[DocumentModelSummary]:
@@ -371,7 +372,7 @@ def list_models(self, **kwargs: Any) -> ItemPaged[DocumentModelSummary]:
371372
:caption: List all models that were built successfully under the Form Recognizer resource.
372373
"""
373374

374-
return self._client.get_models( # type: ignore
375+
return self._client.get_document_models( # type: ignore
375376
cls=kwargs.pop(
376377
"cls",
377378
lambda objs: [DocumentModelSummary._from_generated(x) for x in objs],
@@ -397,7 +398,7 @@ def get_resource_details(self, **kwargs: Any) -> ResourceDetails:
397398
:caption: Get model counts and limits under the Form Recognizer resource.
398399
"""
399400

400-
response = self._client.get_info(**kwargs)
401+
response = self._client.get_resource_details(**kwargs)
401402
return ResourceDetails._from_generated(response.custom_document_models)
402403

403404
@distributed_trace
@@ -422,7 +423,7 @@ def get_model(self, model_id: str, **kwargs: Any) -> DocumentModelDetails:
422423
if not model_id:
423424
raise ValueError("model_id cannot be None or empty.")
424425

425-
response = self._client.get_model(model_id=model_id, **kwargs)
426+
response = self._client.get_document_model(model_id=model_id, **kwargs)
426427
return DocumentModelDetails._from_generated(response)
427428

428429
@distributed_trace

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_generated/_form_recognizer_client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
6060
LATEST_PROFILE = ProfileDefinition({
6161
_PROFILE_TAG: {
6262
None: DEFAULT_API_VERSION,
63-
'authorize_copy_document_model': '2022-06-30-preview',
64-
'begin_analyze_document': '2022-06-30-preview',
65-
'begin_build_document_model': '2022-06-30-preview',
66-
'begin_compose_document_model': '2022-06-30-preview',
67-
'begin_copy_document_model_to': '2022-06-30-preview',
68-
'delete_model': '2022-06-30-preview',
69-
'get_analyze_document_result': '2022-06-30-preview',
70-
'get_info': '2022-06-30-preview',
71-
'get_model': '2022-06-30-preview',
72-
'get_models': '2022-06-30-preview',
73-
'get_operation': '2022-06-30-preview',
74-
'get_operations': '2022-06-30-preview',
63+
'authorize_copy_document_model': '2022-08-31',
64+
'begin_analyze_document': '2022-08-31',
65+
'begin_build_document_model': '2022-08-31',
66+
'begin_compose_document_model': '2022-08-31',
67+
'begin_copy_document_model_to': '2022-08-31',
68+
'delete_document_model': '2022-08-31',
69+
'get_analyze_document_result': '2022-08-31',
70+
'get_document_model': '2022-08-31',
71+
'get_document_models': '2022-08-31',
72+
'get_operation': '2022-08-31',
73+
'get_operations': '2022-08-31',
74+
'get_resource_details': '2022-08-31',
7575
'train_custom_model_async': '2.0',
7676
}},
7777
_PROFILE_TAG + " latest"
@@ -85,7 +85,7 @@ def __init__(
8585
profile=KnownProfiles.default, # type: KnownProfiles
8686
**kwargs # type: Any
8787
):
88-
if api_version == '2022-06-30-preview':
88+
if api_version == '2022-08-31':
8989
base_url = '{endpoint}/formrecognizer'
9090
elif api_version == '2.0':
9191
base_url = '{endpoint}/formrecognizer/v2.0'
@@ -108,12 +108,12 @@ def _models_dict(cls, api_version):
108108
def models(cls, api_version=DEFAULT_API_VERSION):
109109
"""Module depends on the API version:
110110
111-
* 2022-06-30-preview: :mod:`v2022_06_30_preview.models<azure.ai.formrecognizer.v2022_06_30_preview.models>`
111+
* 2022-08-31: :mod:`v2022_08_31.models<azure.ai.formrecognizer.v2022_08_31.models>`
112112
* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
113113
* 2.1: :mod:`v2_1.models<azure.ai.formrecognizer.v2_1.models>`
114114
"""
115-
if api_version == '2022-06-30-preview':
116-
from .v2022_06_30_preview import models
115+
if api_version == '2022-08-31':
116+
from .v2022_08_31 import models
117117
return models
118118
elif api_version == '2.0':
119119
from .v2_0 import models

0 commit comments

Comments
 (0)