Skip to content

Commit 8033835

Browse files
authored
[form recognizer] consistency renames for FormTrainingClient (#11390)
1 parent d27aca7 commit 8033835

18 files changed

+81
-75
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 1.0.0b3 (Unreleased)
44

5+
**Breaking Changes**
6+
7+
- `training_files` parameter of `begin_train_model` is renamed to `training_files_url`
8+
- `use_labels` parameter of `begin_train_model` is renamed to `use_training_labels`
9+
- `list_model_infos` method has been renamed to `list_custom_models`
10+
511
**New features**
612

713
- Authentication using `azure-identity` credentials now supported
@@ -18,7 +24,7 @@
1824

1925
## 1.0.0b1 (2020-04-23)
2026

21-
Version (1.0.0b1) is the first preview of our efforts to create a user-friendly and Pythonic client library for Azure Form Recognizer.
27+
Version (1.0.0b1) is the first preview of our efforts to create a user-friendly and Pythonic client library for Azure Form Recognizer.
2228
This library replaces the package found here: https://pypi.org/project/azure-cognitiveservices-formrecognizer/
2329

2430
For more information about this, and preview releases of other Azure SDK libraries, please visit
@@ -27,7 +33,7 @@ https://azure.github.io/azure-sdk/releases/latest/python.html.
2733
**Breaking changes: New API design**
2834

2935
- New namespace/package name:
30-
- The namespace/package name for the Form Recognizer client library has changed from
36+
- The namespace/package name for the Form Recognizer client library has changed from
3137
`azure.cognitiveservices.formrecognizer` to `azure.ai.formrecognizer`
3238
- Two client design:
3339
- FormRecognizerClient to analyze fields/values on custom forms, receipts, and form content/layout
@@ -38,7 +44,7 @@ https://azure.github.io/azure-sdk/releases/latest/python.html.
3844
- Asynchronous APIs added under `azure.ai.formrecognizer.aio` namespace
3945
- Authentication with API key supported using `AzureKeyCredential("<api_key>")` from `azure.core.credentials`
4046
- New underlying REST pipeline implementation based on the azure-core library
41-
- Client and pipeline configuration is now available via keyword arguments at both the client level, and per-operation.
47+
- Client and pipeline configuration is now available via keyword arguments at both the client level, and per-operation.
4248
See README for a link to optional configuration arguments
4349
- New error hierarchy:
4450
- All service errors will now use the base type: `azure.core.exceptions.HttpResponseError`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ print("Our account has {} custom models, and we can have at most {} custom model
302302
))
303303

304304
# Here we get a paged list of all of our custom models
305-
custom_models = form_training_client.list_model_infos()
305+
custom_models = form_training_client.list_custom_models()
306306
print("We have models with the following ids: {}".format(
307307
", ".join([m.model_id for m in custom_models])
308308
))

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def __init__(self, endpoint, credential, **kwargs):
7777
)
7878

7979
@distributed_trace
80-
def begin_train_model(self, training_files, use_labels=False, **kwargs):
80+
def begin_train_model(self, training_files_url, use_training_labels=False, **kwargs):
8181
# type: (str, Optional[bool], Any) -> LROPoller
82-
"""Create and train a custom model. The request must include a `training_files` parameter that is an
82+
"""Create and train a custom model. The request must include a `training_files_url` parameter that is an
8383
externally accessible Azure storage blob container Uri (preferably a Shared Access Signature Uri).
8484
Models are trained using documents that are of the following content type - 'application/pdf',
8585
'image/jpeg', 'image/png', 'image/tiff'. Other type of content in the container is ignored.
8686
87-
:param str training_files: An Azure Storage blob container's SAS URI.
88-
:param bool use_labels: Whether to train with labels or not. Corresponding labeled files must
87+
:param str training_files_url: An Azure Storage blob container's SAS URI.
88+
:param bool use_training_labels: Whether to train with labels or not. Corresponding labeled files must
8989
exist in the blob container.
9090
:keyword str prefix: A case-sensitive prefix string to filter documents for training.
9191
Use `prefix` to filter documents themselves, or to restrict sub folders for training
@@ -114,8 +114,8 @@ def begin_train_model(self, training_files, use_labels=False, **kwargs):
114114
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
115115
response = self._client.train_custom_model_async( # type: ignore
116116
train_request=TrainRequest(
117-
source=training_files,
118-
use_label_file=use_labels,
117+
source=training_files_url,
118+
use_label_file=use_training_labels,
119119
source_filter=TrainSourceFilter(
120120
prefix=kwargs.pop("prefix", ""),
121121
include_sub_folders=kwargs.pop("include_sub_folders", False),
@@ -166,7 +166,7 @@ def delete_model(self, model_id, **kwargs):
166166
)
167167

168168
@distributed_trace
169-
def list_model_infos(self, **kwargs):
169+
def list_custom_models(self, **kwargs):
170170
# type: (Any) -> Iterable[CustomFormModelInfo]
171171
"""List information for each model, including model id,
172172
model status, and when it was created and last modified.
@@ -178,8 +178,8 @@ def list_model_infos(self, **kwargs):
178178
.. admonition:: Example:
179179
180180
.. literalinclude:: ../samples/sample_manage_custom_models.py
181-
:start-after: [START list_model_infos]
182-
:end-before: [END list_model_infos]
181+
:start-after: [START list_custom_models]
182+
:end-before: [END list_custom_models]
183183
:language: python
184184
:dedent: 8
185185
:caption: List model information for each model on the account.

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ def __init__(
8383
@distributed_trace_async
8484
async def train_model(
8585
self,
86-
training_files: str,
87-
use_labels: Optional[bool] = False,
86+
training_files_url: str,
87+
use_training_labels: Optional[bool] = False,
8888
**kwargs: Any
8989
) -> CustomFormModel:
90-
"""Create and train a custom model. The request must include a `training_files` parameter that is an
90+
"""Create and train a custom model. The request must include a `training_files_url` parameter that is an
9191
externally accessible Azure storage blob container Uri (preferably a Shared Access Signature Uri).
9292
Models are trained using documents that are of the following content type - 'application/pdf',
9393
'image/jpeg', 'image/png', 'image/tiff'. Other type of content in the container is ignored.
9494
95-
:param str training_files: An Azure Storage blob container's SAS URI.
96-
:param bool use_labels: Whether to train with labels or not. Corresponding labeled files must
95+
:param str training_files_url: An Azure Storage blob container's SAS URI.
96+
:param bool use_training_labels: Whether to train with labels or not. Corresponding labeled files must
9797
exist in the blob container.
9898
:keyword str prefix: A case-sensitive prefix string to filter documents for training.
9999
Use `prefix` to filter documents themselves, or to restrict sub folders for training
@@ -121,8 +121,8 @@ async def train_model(
121121
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
122122
response = await self._client.train_custom_model_async(
123123
train_request=TrainRequest(
124-
source=training_files,
125-
use_label_file=use_labels,
124+
source=training_files_url,
125+
use_label_file=use_training_labels,
126126
source_filter=TrainSourceFilter(
127127
prefix=kwargs.pop("prefix", ""),
128128
include_sub_folders=kwargs.pop("include_sub_folders", False)
@@ -171,7 +171,7 @@ async def delete_model(self, model_id: str, **kwargs: Any) -> None:
171171
)
172172

173173
@distributed_trace
174-
def list_model_infos(self, **kwargs: Any) -> AsyncIterable[CustomFormModelInfo]:
174+
def list_custom_models(self, **kwargs: Any) -> AsyncIterable[CustomFormModelInfo]:
175175
"""List information for each model, including model id,
176176
model status, and when it was created and last modified.
177177
@@ -182,8 +182,8 @@ def list_model_infos(self, **kwargs: Any) -> AsyncIterable[CustomFormModelInfo]:
182182
.. admonition:: Example:
183183
184184
.. literalinclude:: ../samples/async_samples/sample_manage_custom_models_async.py
185-
:start-after: [START list_model_infos_async]
186-
:end-before: [END list_model_infos_async]
185+
:start-after: [START list_custom_models_async]
186+
:end-before: [END list_custom_models_async]
187187
:language: python
188188
:dedent: 12
189189
:caption: List model information for each model on the account.

sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_manage_custom_models_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ async def manage_custom_models(self):
4747
# [END get_account_properties_async]
4848

4949
# Next, we get a paged list of all of our custom models
50-
# [START list_model_infos_async]
51-
custom_models = form_training_client.list_model_infos()
50+
# [START list_custom_models_async]
51+
custom_models = form_training_client.list_custom_models()
5252

5353
print("We have models with the following ids:")
5454

@@ -58,7 +58,7 @@ async def manage_custom_models(self):
5858
print(model.model_id)
5959
if not first_model:
6060
first_model = model
61-
# [END list_model_infos_async]
61+
# [END list_custom_models_async]
6262

6363
# Now we'll get the first custom model in the paged list
6464
# [START get_custom_model_async]

sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_with_labels_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def train_model_with_labels(self):
4646
# [END create_form_training_client_async]
4747
async with form_training_client:
4848

49-
model = await form_training_client.train_model(self.container_sas_url, use_labels=True)
49+
model = await form_training_client.train_model(self.container_sas_url, use_training_labels=True)
5050
# Custom model information
5151
print("Model ID: {}".format(model.model_id))
5252
print("Status: {}".format(model.status))

sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_without_labels_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def train_model_without_labels(self):
4242
self.endpoint, AzureKeyCredential(self.key)
4343
) as form_training_client:
4444

45-
# Default for train_model is `use_labels=False`
45+
# Default for train_model is `use_training_labels=False`
4646
model = await form_training_client.train_model(self.container_sas_url)
4747

4848
# Custom model information

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_manage_custom_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def manage_custom_models(self):
4444
# [END get_account_properties]
4545

4646
# Next, we get a paged list of all of our custom models
47-
# [START list_model_infos]
48-
custom_models = form_training_client.list_model_infos()
47+
# [START list_custom_models]
48+
custom_models = form_training_client.list_custom_models()
4949

5050
print("We have models with the following ids:")
5151

@@ -54,7 +54,7 @@ def manage_custom_models(self):
5454
print(first_model.model_id)
5555
for model in custom_models:
5656
print(model.model_id)
57-
# [END list_model_infos]
57+
# [END list_custom_models]
5858

5959
# Now we'll get the first custom model in the paged list
6060
# [START get_custom_model]

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_with_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def train_model_with_labels(self):
4242
form_training_client = FormTrainingClient(self.endpoint, AzureKeyCredential(self.key))
4343
# [END create_form_training_client]
4444

45-
poller = form_training_client.begin_train_model(self.container_sas_url, use_labels=True)
45+
poller = form_training_client.begin_train_model(self.container_sas_url, use_training_labels=True)
4646
model = poller.result()
4747

4848
# Custom model information

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_without_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def train_model_without_labels(self):
3939

4040
form_training_client = FormTrainingClient(self.endpoint, AzureKeyCredential(self.key))
4141

42-
# Default for begin_train_model is `use_labels=False`
42+
# Default for begin_train_model is `use_training_labels=False`
4343
poller = form_training_client.begin_train_model(self.container_sas_url)
4444
model = poller.result()
4545

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_custom_form_labeled(self, client, container_sas_url):
128128

129129
poller = training_client.begin_train_model(
130130
container_sas_url,
131-
use_labels=True
131+
use_training_labels=True
132132
)
133133
model = poller.result()
134134

@@ -154,7 +154,7 @@ def test_custom_form_multipage_labeled(self, client, container_sas_url):
154154

155155
poller = training_client.begin_train_model(
156156
container_sas_url,
157-
use_labels=True
157+
use_training_labels=True
158158
)
159159
model = poller.result()
160160

@@ -258,7 +258,7 @@ def callback(raw_response, _, headers):
258258
def test_custom_form_labeled_transform(self, client, container_sas_url):
259259
training_client = client.get_form_training_client()
260260

261-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
261+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
262262
model = poller.result()
263263

264264
responses = []
@@ -295,7 +295,7 @@ def callback(raw_response, _, headers):
295295
def test_custom_form_multipage_labeled_transform(self, client, container_sas_url):
296296
training_client = client.get_form_training_client()
297297

298-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
298+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
299299
model = poller.result()
300300

301301
responses = []

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def test_custom_form_multipage_unlabeled(self, client, container_sas_url):
121121
async def test_custom_form_labeled(self, client, container_sas_url):
122122
training_client = client.get_form_training_client()
123123

124-
model = await training_client.train_model(container_sas_url, use_labels=True)
124+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
125125

126126
with open(self.form_jpg, "rb") as fd:
127127
myfile = fd.read()
@@ -144,7 +144,7 @@ async def test_custom_form_multipage_labeled(self, client, container_sas_url):
144144

145145
model = await training_client.train_model(
146146
container_sas_url,
147-
use_labels=True
147+
use_training_labels=True
148148
)
149149

150150
with open(self.multipage_invoice_pdf, "rb") as fd:
@@ -246,7 +246,7 @@ def callback(raw_response, _, headers):
246246
async def test_form_labeled_transform(self, client, container_sas_url):
247247
training_client = client.get_form_training_client()
248248

249-
model = await training_client.train_model(container_sas_url, use_labels=True)
249+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
250250

251251
responses = []
252252

@@ -282,7 +282,7 @@ def callback(raw_response, _, headers):
282282
async def test_custom_forms_multipage_labeled_transform(self, client, container_sas_url):
283283
training_client = client.get_form_training_client()
284284

285-
model = await training_client.train_model(container_sas_url, use_labels=True)
285+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
286286

287287
responses = []
288288

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_pass_stream_into_url(self, resource_group, location, form_recognizer_ac
5454
def test_custom_form_bad_url(self, client, container_sas_url):
5555
training_client = client.get_form_training_client()
5656

57-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
57+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
5858
model = poller.result()
5959

6060
with self.assertRaises(HttpResponseError):
@@ -115,7 +115,7 @@ def test_form_multipage_unlabeled(self, client, container_sas_url, blob_sas_url)
115115
def test_custom_form_labeled(self, client, container_sas_url):
116116
training_client = client.get_form_training_client()
117117

118-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
118+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
119119
model = poller.result()
120120

121121
poller = client.begin_recognize_custom_forms_from_url(model.model_id, self.form_url_jpg)
@@ -137,7 +137,7 @@ def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_url):
137137

138138
poller = training_client.begin_train_model(
139139
container_sas_url,
140-
use_labels=True
140+
use_training_labels=True
141141
)
142142
model = poller.result()
143143

@@ -233,7 +233,7 @@ def callback(raw_response, _, headers):
233233
def test_form_labeled_transform(self, client, container_sas_url):
234234
training_client = client.get_form_training_client()
235235

236-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
236+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
237237
model = poller.result()
238238

239239
responses = []
@@ -267,7 +267,7 @@ def callback(raw_response, _, headers):
267267
def test_custom_form_multipage_labeled_transform(self, client, container_sas_url, blob_sas_url):
268268
training_client = client.get_form_training_client()
269269

270-
poller = training_client.begin_train_model(container_sas_url, use_labels=True)
270+
poller = training_client.begin_train_model(container_sas_url, use_training_labels=True)
271271
model = poller.result()
272272

273273
responses = []

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_custom_forms_from_url_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def test_pass_stream_into_url(self, resource_group, location, form_recogni
5454
async def test_form_bad_url(self, client, container_sas_url):
5555
training_client = client.get_form_training_client()
5656

57-
model = await training_client.train_model(container_sas_url, use_labels=True)
57+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
5858

5959
with self.assertRaises(HttpResponseError):
6060
form = await client.recognize_custom_forms_from_url(
@@ -109,7 +109,7 @@ async def test_custom_form_multipage_unlabeled(self, client, container_sas_url,
109109
async def test_form_labeled(self, client, container_sas_url):
110110
training_client = client.get_form_training_client()
111111

112-
model = await training_client.train_model(container_sas_url, use_labels=True)
112+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
113113

114114
form = await client.recognize_custom_forms_from_url(model.model_id, self.form_url_jpg)
115115

@@ -129,7 +129,7 @@ async def test_form_multipage_labeled(self, client, container_sas_url, blob_sas_
129129

130130
model = await training_client.train_model(
131131
container_sas_url,
132-
use_labels=True
132+
use_training_labels=True
133133
)
134134

135135
forms = await client.recognize_custom_forms_from_url(
@@ -218,7 +218,7 @@ def callback(raw_response, _, headers):
218218
async def test_form_labeled_transform(self, client, container_sas_url):
219219
training_client = client.get_form_training_client()
220220

221-
model = await training_client.train_model(container_sas_url, use_labels=True)
221+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
222222

223223
responses = []
224224

@@ -251,7 +251,7 @@ def callback(raw_response, _, headers):
251251
async def test_multipage_labeled_transform(self, client, container_sas_url, blob_sas_url):
252252
training_client = client.get_form_training_client()
253253

254-
model = await training_client.train_model(container_sas_url, use_labels=True)
254+
model = await training_client.train_model(container_sas_url, use_training_labels=True)
255255

256256
responses = []
257257

0 commit comments

Comments
 (0)