Skip to content

Commit d4d12b9

Browse files
[formrecognizer] Adding 2022-01-30-preview work (Azure#22912)
* adding FR 2022-01-30-preview work * update shared requirements
1 parent 8fb240c commit d4d12b9

File tree

246 files changed

+99951
-83654
lines changed

Some content is hidden

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

246 files changed

+99951
-83654
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Release History
22

3-
## 3.2.0b3 (Unreleased)
3+
## 3.2.0b3 (2022-02-10)
44

55
### Features Added
6+
- Added new `CurrencyValue` model to represent the amount and currency symbol values found in documents.
7+
- Added `DocumentBuildMode` enum with values `template` and `neural`. These enum values can be passed in for the `build_mode` parameter in `begin_build_model()`.
8+
- Added `api_version` and `tags` properties on `ModelOperation`, `ModelOperationInfo`, `DocumentModel`, `DocumentModelInfo`.
9+
- Added `build_mode` property on `DocTypeInfo`.
10+
- Added a `tags` keyword argument to `begin_build_model()`, `begin_create_composed_model()`, and `get_copy_authorization()`.
11+
- Added `languages` property on `AnalyzeResult`.
12+
- Added model `DocumentLanguage` that includes information about the detected languages found in a document.
13+
- Added `sample_analyze_read.py` and `sample_analyze_read_async.py` under the `v3.2-beta` samples directory. These samples use the new `prebuilt-read` model added by the service.
14+
- Added `sample_analyze_tax_us_w2.py` and `sample_analyze_tax_us_w2_async.py` under the `v3.2-beta` samples directory. These samples use the new `prebuilt-tax.us.w2` model added by the service.
615

716
### Breaking Changes
8-
9-
### Bugs Fixed
10-
- Default the `percent_completed` property to 0 when not returned with model operation information.
17+
- Added new required parameter `build_mode` to `begin_build_model()`.
18+
- Some models that previously returned float for currency related fields may now return a `CurrencyValue`. TIP: Use `get_model()` to see updated prebuilt model schemas.
1119

1220
### Other Changes
1321
- Python 2.7 is no longer supported in this release. Please use Python 3.6 or later.
22+
- Bumped `azure-core` minimum dependency version from `1.13.0` to `1.20.1`.
23+
- Updated samples that call `begin_build_model()` to send the `build_mode` parameter.
1424

1525
## 3.2.0b2 (2021-11-09)
1626

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
AnalyzeResult,
4141
AnalyzedDocument,
4242
BoundingRegion,
43+
CurrencyValue,
44+
DocumentBuildMode,
4345
DocumentContentElement,
4446
DocumentEntity,
4547
DocumentField,
4648
DocumentKeyValuePair,
4749
DocumentKeyValueElement,
50+
DocumentLanguage,
4851
DocumentLine,
4952
DocumentPage,
5053
DocumentSelectionMark,
@@ -100,11 +103,14 @@
100103
"AnalyzeResult",
101104
"AnalyzedDocument",
102105
"BoundingRegion",
106+
"CurrencyValue",
107+
"DocumentBuildMode",
103108
"DocumentContentElement",
104109
"DocumentEntity",
105110
"DocumentField",
106111
"DocumentKeyValueElement",
107112
"DocumentKeyValuePair",
113+
"DocumentLanguage",
108114
"DocumentLine",
109115
"DocumentPage",
110116
"DocumentSelectionMark",

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
@@ -10,7 +10,7 @@ class DocumentAnalysisApiVersion(str, Enum):
1010
"""Form Recognizer API versions supported by DocumentAnalysisClient and DocumentModelAdministrationClient."""
1111

1212
#: This is the default version
13-
V2021_09_30_PREVIEW = "2021-09-30-preview"
13+
V2022_01_30_PREVIEW = "2022-01-30-preview"
1414

1515

1616
class FormRecognizerApiVersion(str, Enum):

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DocumentAnalysisClient(FormRecognizerClientBase):
6363
def __init__(self, endpoint, credential, **kwargs):
6464
# type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None
6565
api_version = kwargs.pop(
66-
"api_version", DocumentAnalysisApiVersion.V2021_09_30_PREVIEW
66+
"api_version", DocumentAnalysisApiVersion.V2022_01_30_PREVIEW
6767
)
6868
super(DocumentAnalysisClient, self).__init__(
6969
endpoint=endpoint,
@@ -125,7 +125,7 @@ def begin_analyze_document(self, model, document, **kwargs):
125125
cls = kwargs.pop("cls", self._analyze_document_callback)
126126
continuation_token = kwargs.pop("continuation_token", None)
127127

128-
return self._client.begin_analyze_document(
128+
return self._client.begin_analyze_document( # type: ignore
129129
model_id=model,
130130
analyze_request=document,
131131
content_type="application/octet-stream",
@@ -174,7 +174,7 @@ def begin_analyze_document_from_url(self, model, document_url, **kwargs):
174174
cls = kwargs.pop("cls", self._analyze_document_callback)
175175
continuation_token = kwargs.pop("continuation_token", None)
176176

177-
return self._client.begin_analyze_document(
177+
return self._client.begin_analyze_document( # type: ignore
178178
model_id=model,
179179
analyze_request={"url_source": document_url},
180180
string_index_type="unicodeCodePoint",

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ._form_base_client import FormRecognizerClientBase
2828
from ._document_analysis_client import DocumentAnalysisClient
2929
from ._models import (
30+
DocumentBuildMode,
3031
DocumentModel,
3132
DocumentModelInfo,
3233
ModelOperation,
@@ -85,7 +86,7 @@ class DocumentModelAdministrationClient(FormRecognizerClientBase):
8586
def __init__(self, endpoint, credential, **kwargs):
8687
# type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None
8788
api_version = kwargs.pop(
88-
"api_version", DocumentAnalysisApiVersion.V2021_09_30_PREVIEW
89+
"api_version", DocumentAnalysisApiVersion.V2022_01_30_PREVIEW
8990
)
9091
super(DocumentModelAdministrationClient, self).__init__(
9192
endpoint=endpoint,
@@ -96,8 +97,8 @@ def __init__(self, endpoint, credential, **kwargs):
9697
)
9798

9899
@distributed_trace
99-
def begin_build_model(self, source, **kwargs):
100-
# type: (str, Any) -> DocumentModelAdministrationLROPoller[DocumentModel]
100+
def begin_build_model(self, source, build_mode, **kwargs):
101+
# type: (str, Union[str, DocumentBuildMode], Any) -> DocumentModelAdministrationLROPoller[DocumentModel]
101102
"""Build a custom model.
102103
103104
The request must include a `source` parameter that is an
@@ -108,17 +109,24 @@ def begin_build_model(self, source, **kwargs):
108109
:param str source: An Azure Storage blob container's SAS URI. A container URI (without SAS)
109110
can be used if the container is public. For more information on setting up a training data set, see:
110111
https://aka.ms/azsdk/formrecognizer/buildtrainingset
112+
:param build_mode: The custom model build mode. Possible values include: "template", "neural".
113+
:type build_mode: str or :class:`~azure.ai.formrecognizer.DocumentBuildMode`
111114
:keyword str model_id: A unique ID for your model. If not specified, a model ID will be created for you.
112115
:keyword str description: An optional description to add to the model.
113116
:keyword str prefix: A case-sensitive prefix string to filter documents in the source path.
114117
For example, when using an Azure storage blob URI, use the prefix to restrict sub folders.
115118
`prefix` should end in '/' to avoid cases where filenames share the same prefix.
119+
:keyword tags: List of user defined key-value tag attributes associated with the model.
120+
:paramtype tags: dict[str, str]
116121
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
117122
:return: An instance of an DocumentModelAdministrationLROPoller. Call `result()` on the poller
118123
object to return a :class:`~azure.ai.formrecognizer.DocumentModel`.
119124
:rtype: ~azure.ai.formrecognizer.DocumentModelAdministrationLROPoller[DocumentModel]
120125
:raises ~azure.core.exceptions.HttpResponseError:
121126
127+
.. versionadded:: v2022-01-30-preview
128+
The *tags* keyword argument
129+
122130
.. admonition:: Example:
123131
124132
.. literalinclude:: ../samples/v3.2-beta/sample_build_model.py
@@ -140,6 +148,7 @@ def callback(raw_response, _, headers): # pylint: disable=unused-argument
140148

141149
description = kwargs.pop("description", None)
142150
model_id = kwargs.pop("model_id", None)
151+
tags = kwargs.pop("tags", None)
143152
cls = kwargs.pop("cls", callback)
144153
continuation_token = kwargs.pop("continuation_token", None)
145154
polling_interval = kwargs.pop(
@@ -152,7 +161,9 @@ def callback(raw_response, _, headers): # pylint: disable=unused-argument
152161
return self._client.begin_build_document_model( # type: ignore
153162
build_request=self._generated_models.BuildDocumentModelRequest(
154163
model_id=model_id,
164+
build_mode=build_mode,
155165
description=description,
166+
tags=tags,
156167
azure_blob_source=self._generated_models.AzureBlobContentSource(
157168
container_url=source,
158169
prefix=kwargs.pop("prefix", None),
@@ -181,12 +192,17 @@ def begin_create_composed_model(self, model_ids, **kwargs):
181192
:keyword str model_id: A unique ID for your composed model.
182193
If not specified, a model ID will be created for you.
183194
:keyword str description: An optional description to add to the model.
195+
:keyword tags: List of user defined key-value tag attributes associated with the model.
196+
:paramtype tags: dict[str, str]
184197
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
185198
:return: An instance of an DocumentModelAdministrationLROPoller. Call `result()` on the poller
186199
object to return a :class:`~azure.ai.formrecognizer.DocumentModel`.
187200
:rtype: ~azure.ai.formrecognizer.DocumentModelAdministrationLROPoller[DocumentModel]
188201
:raises ~azure.core.exceptions.HttpResponseError:
189202
203+
.. versionadded:: v2022-01-30-preview
204+
The *tags* keyword argument
205+
190206
.. admonition:: Example:
191207
192208
.. literalinclude:: ../samples/v3.2-beta/sample_create_composed_model.py
@@ -210,6 +226,7 @@ def _compose_callback(
210226

211227
model_id = kwargs.pop("model_id", None)
212228
description = kwargs.pop("description", None)
229+
tags = kwargs.pop("tags", None)
213230
continuation_token = kwargs.pop("continuation_token", None)
214231
polling_interval = kwargs.pop(
215232
"polling_interval", self._client._config.polling_interval
@@ -218,10 +235,11 @@ def _compose_callback(
218235
if model_id is None:
219236
model_id = str(uuid.uuid4())
220237

221-
return self._client.begin_compose_document_model(
238+
return self._client.begin_compose_document_model( # type: ignore
222239
compose_request=self._generated_models.ComposeDocumentModelRequest(
223240
model_id=model_id,
224241
description=description,
242+
tags=tags,
225243
component_models=[
226244
self._generated_models.ComponentModelInfo(model_id=model_id)
227245
for model_id in model_ids
@@ -250,20 +268,26 @@ def get_copy_authorization(self, **kwargs):
250268
:keyword str model_id: A unique ID for your copied model.
251269
If not specified, a model ID will be created for you.
252270
:keyword str description: An optional description to add to the model.
271+
:keyword tags: List of user defined key-value tag attributes associated with the model.
272+
:paramtype tags: dict[str, str]
253273
:return: A dictionary with values necessary for the copy authorization.
254274
:rtype: Dict[str, str]
255275
:raises ~azure.core.exceptions.HttpResponseError:
276+
277+
.. versionadded:: v2022-01-30-preview
278+
The *tags* keyword argument
256279
"""
257280

258281
model_id = kwargs.pop("model_id", None)
259282
description = kwargs.pop("description", None)
283+
tags = kwargs.pop("tags", None)
260284

261285
if model_id is None:
262286
model_id = str(uuid.uuid4())
263287

264288
response = self._client.authorize_copy_document_model(
265289
authorize_copy_request=self._generated_models.AuthorizeCopyRequest(
266-
model_id=model_id, description=description
290+
model_id=model_id, description=description, tags=tags
267291
),
268292
**kwargs
269293
)
@@ -322,7 +346,7 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument
322346
)
323347
continuation_token = kwargs.pop("continuation_token", None)
324348

325-
return self._client.begin_copy_document_model_to(
349+
return self._client.begin_copy_document_model_to( # type: ignore
326350
model_id=model_id,
327351
copy_to_request=self._generated_models.CopyAuthorization(
328352
target_resource_id=target["targetResourceId"],
@@ -389,7 +413,7 @@ def list_models(self, **kwargs):
389413
:caption: List all models that were built successfully under the Form Recognizer resource.
390414
"""
391415

392-
return self._client.get_models(
416+
return self._client.get_models( # type: ignore
393417
cls=kwargs.pop(
394418
"cls",
395419
lambda objs: [DocumentModelInfo._from_generated(x) for x in objs],
@@ -468,7 +492,7 @@ def list_operations(self, **kwargs):
468492
:caption: List all document model operations in the past 24 hours.
469493
"""
470494

471-
return self._client.get_operations(
495+
return self._client.get_operations( # type: ignore
472496
cls=kwargs.pop(
473497
"cls",
474498
lambda objs: [ModelOperationInfo._from_generated(x) for x in objs],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument
165165
deserialization_callback=deserialization_callback,
166166
)
167167

168-
response = self._client.train_custom_model_async(
168+
response = self._client.train_custom_model_async( # type: ignore
169169
train_request=self._generated_models.TrainRequest(
170170
source=training_files_url,
171171
use_label_file=use_training_labels,
@@ -486,7 +486,7 @@ def _compose_callback(
486486
)
487487
continuation_token = kwargs.pop("continuation_token", None)
488488
try:
489-
return self._client.begin_compose_custom_models_async(
489+
return self._client.begin_compose_custom_models_async( # type: ignore
490490
{"model_ids": model_ids, "model_name": model_name},
491491
cls=kwargs.pop("cls", _compose_callback),
492492
polling=LROBasePolling(

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class FormRecognizerClientConfiguration(Configuration):
2929
3030
:param credential: Credential needed for the client to connect to Azure.
3131
:type credential: ~azure.core.credentials.TokenCredential
32-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for
33-
example: https://westus2.api.cognitive.microsoft.com).
32+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
3433
:type endpoint: str
3534
"""
3635

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from typing import Any, Optional
2525

2626
from azure.core.credentials import TokenCredential
27-
from azure.core.pipeline.transport import HttpRequest, HttpResponse
2827

2928
class _SDKClient(object):
3029
def __init__(self, *args, **kwargs):
@@ -34,7 +33,7 @@ def __init__(self, *args, **kwargs):
3433
pass
3534

3635
class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMixin, _SDKClient):
37-
"""Extracts content, layout, and structured data from documents.
36+
"""Extracts information from forms and images into structured data.
3837
3938
This ready contains multiple API versions, to help you deal with all of the Azure clouds
4039
(Azure Stack, Azure Government, Azure China, etc.).
@@ -46,8 +45,7 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
4645
4746
:param credential: Credential needed for the client to connect to Azure.
4847
:type credential: ~azure.core.credentials.TokenCredential
49-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for
50-
example: https://westus2.api.cognitive.microsoft.com).
48+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).
5149
:type endpoint: str
5250
:param api_version: API version to use if no profile is provided, or if missing in profile.
5351
:type api_version: str
@@ -56,11 +54,24 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
5654
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
5755
"""
5856

59-
DEFAULT_API_VERSION = '2021-09-30-preview'
57+
DEFAULT_API_VERSION = '2.1'
6058
_PROFILE_TAG = "azure.ai.formrecognizer.FormRecognizerClient"
6159
LATEST_PROFILE = ProfileDefinition({
6260
_PROFILE_TAG: {
6361
None: DEFAULT_API_VERSION,
62+
'authorize_copy_document_model': '2022-01-30-preview',
63+
'begin_analyze_document': '2022-01-30-preview',
64+
'begin_build_document_model': '2022-01-30-preview',
65+
'begin_compose_document_model': '2022-01-30-preview',
66+
'begin_copy_document_model_to': '2022-01-30-preview',
67+
'delete_model': '2022-01-30-preview',
68+
'get_analyze_document_result': '2022-01-30-preview',
69+
'get_info': '2022-01-30-preview',
70+
'get_model': '2022-01-30-preview',
71+
'get_models': '2022-01-30-preview',
72+
'get_operation': '2022-01-30-preview',
73+
'get_operations': '2022-01-30-preview',
74+
'train_custom_model_async': '2.0',
6475
}},
6576
_PROFILE_TAG + " latest"
6677
)
@@ -73,7 +84,7 @@ def __init__(
7384
profile=KnownProfiles.default, # type: KnownProfiles
7485
**kwargs # type: Any
7586
):
76-
if api_version == '2021-09-30-preview':
87+
if api_version == '2022-01-30-preview':
7788
base_url = '{endpoint}/formrecognizer'
7889
elif api_version == '2.0':
7990
base_url = '{endpoint}/formrecognizer/v2.0'
@@ -96,12 +107,12 @@ def _models_dict(cls, api_version):
96107
def models(cls, api_version=DEFAULT_API_VERSION):
97108
"""Module depends on the API version:
98109
99-
* 2021-09-30-preview: :mod:`v2021_09_30_preview.models<azure.ai.formrecognizer.v2021_09_30_preview.models>`
110+
* 2022-01-30-preview: :mod:`v2022_01_30_preview.models<azure.ai.formrecognizer.v2022_01_30_preview.models>`
100111
* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
101112
* 2.1: :mod:`v2_1.models<azure.ai.formrecognizer.v2_1.models>`
102113
"""
103-
if api_version == '2021-09-30-preview':
104-
from .v2021_09_30_preview import models
114+
if api_version == '2022-01-30-preview':
115+
from .v2022_01_30_preview import models
105116
return models
106117
elif api_version == '2.0':
107118
from .v2_0 import models

0 commit comments

Comments
 (0)