Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[form recognizer] Move get_client method from FormRecognizer -> FormTraining #11423

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- `training_files` parameter of `begin_train_model` is renamed to `training_files_url`
- `use_labels` parameter of `begin_train_model` is renamed to `use_training_labels`
- `list_model_infos` method has been renamed to `list_custom_models`
- Removed `get_form_training_client` from `FormRecognizerClient`
- Added `get_form_recognizer_client` to `FormTrainingClient`

**New features**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from ._helpers import get_content_type, get_authentication_policy, error_map, POLLING_INTERVAL
from ._user_agent import USER_AGENT
from ._polling import AnalyzePolling
from ._form_training_client import FormTrainingClient
if TYPE_CHECKING:
from azure.core.credentials import AzureKeyCredential, TokenCredential

Expand Down Expand Up @@ -63,13 +62,11 @@ class FormRecognizerClient(object):

def __init__(self, endpoint, credential, **kwargs):
# type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None
self._endpoint = endpoint
self._credential = credential

authentication_policy = get_authentication_policy(credential)
self._client = FormRecognizer(
endpoint=self._endpoint,
credential=self._credential,
endpoint=endpoint,
credential=credential,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
**kwargs
Expand Down Expand Up @@ -344,19 +341,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume
**kwargs
)

def get_form_training_client(self, **kwargs):
# type: (Any) -> FormTrainingClient
"""Get an instance of a FormTrainingClient from FormRecognizerClient.

:rtype: ~azure.ai.formrecognizer.FormTrainingClient
:return: A FormTrainingClient
"""
return FormTrainingClient(
endpoint=self._endpoint,
credential=self._credential,
**kwargs
)

def close(self):
# type: () -> None
"""Close the :class:`~azure.ai.formrecognizer.FormRecognizerClient` session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from ._polling import TrainingPolling
from ._user_agent import USER_AGENT
from ._form_recognizer_client import FormRecognizerClient
if TYPE_CHECKING:
from azure.core.credentials import AzureKeyCredential, TokenCredential
from azure.core.pipeline.transport import HttpResponse
Expand Down Expand Up @@ -66,11 +67,12 @@ class FormTrainingClient(object):

def __init__(self, endpoint, credential, **kwargs):
# type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None

self._endpoint = endpoint
self._credential = credential
authentication_policy = get_authentication_policy(credential)
self._client = FormRecognizer(
endpoint=endpoint,
credential=credential,
endpoint=self._endpoint,
credential=self._credential,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
**kwargs
Expand Down Expand Up @@ -235,6 +237,19 @@ def get_custom_model(self, model_id, **kwargs):
response = self._client.get_custom_model(model_id=model_id, include_keys=True, error_map=error_map, **kwargs)
return CustomFormModel._from_generated(response)

def get_form_recognizer_client(self, **kwargs):
# type: (Any) -> FormRecognizerClient
"""Get an instance of a FormRecognizerClient from FormTrainingClient.

:rtype: ~azure.ai.formrecognizer.FormRecognizerClient
:return: A FormRecognizerClient
"""
return FormRecognizerClient(
endpoint=self._endpoint,
credential=self._credential,
**kwargs
)

def close(self):
# type: () -> None
"""Close the :class:`~azure.ai.formrecognizer.FormTrainingClient` session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.polling.async_base_polling import AsyncLROBasePolling
from ._form_training_client_async import FormTrainingClient
from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer
from .._response_handlers import (
prepare_us_receipt,
Expand Down Expand Up @@ -75,11 +74,9 @@ def __init__(
) -> None:

authentication_policy = get_authentication_policy(credential)
self._endpoint = endpoint
self._credential = credential
self._client = FormRecognizer(
endpoint=self._endpoint,
credential=self._credential,
endpoint=endpoint,
credential=credential,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
**kwargs
Expand Down Expand Up @@ -360,18 +357,6 @@ def analyze_callback(raw_response, _, headers): # pylint: disable=unused-argume
**kwargs
)

def get_form_training_client(self, **kwargs: Any) -> FormTrainingClient:
"""Get an instance of a FormTrainingClient from FormRecognizerClient.

:rtype: ~azure.ai.formrecognizer.aio.FormTrainingClient
:return: A FormTrainingClient
"""
return FormTrainingClient(
endpoint=self._endpoint,
credential=self._credential,
**kwargs
)

async def __aenter__(self) -> "FormRecognizerClient":
await self._client.__aenter__()
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from azure.core.polling.async_base_polling import AsyncLROBasePolling
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async
from ._form_recognizer_client_async import FormRecognizerClient
from .._generated.aio._form_recognizer_client_async import FormRecognizerClient as FormRecognizer
from .._generated.models import TrainRequest, TrainSourceFilter
from .._generated.models import Model
Expand Down Expand Up @@ -70,11 +71,13 @@ def __init__(
credential: Union["AzureKeyCredential", "AsyncTokenCredential"],
**kwargs: Any
) -> None:
self._endpoint = endpoint
self._credential = credential

authentication_policy = get_authentication_policy(credential)
self._client = FormRecognizer(
endpoint=endpoint,
credential=credential,
endpoint=self._endpoint,
credential=self._credential,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
**kwargs
Expand Down Expand Up @@ -242,6 +245,18 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode
)
return CustomFormModel._from_generated(response)

def get_form_recognizer_client(self, **kwargs: Any) -> FormRecognizerClient:
"""Get an instance of a FormRecognizerClient from FormTrainingClient.

:rtype: ~azure.ai.formrecognizer.aio.FormRecognizerClient
:return: A FormRecognizerClient
"""
return FormRecognizerClient(
endpoint=self._endpoint,
credential=self._credential,
**kwargs
)

async def __aenter__(self) -> "FormTrainingClient":
await self._client.__aenter__()
return self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: GET
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary
response:
body:
string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:33Z"}}'
headers:
apim-request-id:
- 49d7757e-2cea-4126-8660-1b64832e48d7
content-type:
- application/json; charset=utf-8
date:
- Wed, 13 May 2020 16:13:32 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '5109'
status:
code: 200
message: OK
- request:
body: '{"source": "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/master/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-allinone.jpg"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '172'
Content-Type:
- application/json
User-Agent:
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: POST
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyze?includeTextDetails=false
response:
body:
string: ''
headers:
apim-request-id:
- 7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
content-length:
- '0'
date:
- Wed, 13 May 2020 16:13:34 GMT
operation-location:
- https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '1478'
status:
code: 202
message: Accepted
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: GET
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
response:
body:
string: '{"status":"running","createdDateTime":"2020-05-13T16:13:34Z","lastUpdatedDateTime":"2020-05-13T16:13:35Z"}'
headers:
apim-request-id:
- 2f458f0e-eccf-4da2-ab90-05c85f13f58b
content-type:
- application/json; charset=utf-8
date:
- Wed, 13 May 2020 16:13:40 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '138'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: GET
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/prebuilt/receipt/analyzeResults/7f8f4fe8-1330-4bb1-8030-9e96ca52adc2
response:
body:
string: '{"status":"succeeded","createdDateTime":"2020-05-13T16:13:34Z","lastUpdatedDateTime":"2020-05-13T16:13:43Z","analyzeResult":{"version":"2.0.0","readResults":[{"page":1,"angle":0.6893,"width":1688,"height":3000,"unit":"pixel","language":"en"}],"documentResults":[{"docType":"prebuilt:receipt","pageRange":[1,1],"fields":{"ReceiptType":{"type":"string","valueString":"Itemized","confidence":0.692},"MerchantName":{"type":"string","valueString":"Contoso
Contoso","text":"Contoso Contoso","boundingBox":[378.2,292.4,1117.7,468.3,1035.7,812.7,296.3,636.8],"page":1,"confidence":0.613},"MerchantAddress":{"type":"string","valueString":"123
Main Street Redmond, WA 98052","text":"123 Main Street Redmond, WA 98052","boundingBox":[302,675.8,848.1,793.7,809.9,970.4,263.9,852.5],"page":1,"confidence":0.99},"MerchantPhoneNumber":{"type":"phoneNumber","valuePhoneNumber":"+19876543210","text":"987-654-3210","boundingBox":[278,1004,656.3,1054.7,646.8,1125.3,268.5,1074.7],"page":1,"confidence":0.99},"TransactionDate":{"type":"date","valueDate":"2019-06-10","text":"6/10/2019","boundingBox":[265.1,1228.4,525,1247,518.9,1332.1,259,1313.5],"page":1,"confidence":0.99},"TransactionTime":{"type":"time","valueTime":"13:59:00","text":"13:59","boundingBox":[541,1248,677.3,1261.5,668.9,1346.5,532.6,1333],"page":1,"confidence":0.977},"Items":{"type":"array","valueArray":[{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[245.1,1581.5,300.9,1585.1,295,1676,239.2,1672.4],"page":1,"confidence":0.92},"Name":{"type":"string","valueString":"Cappuccino","text":"Cappuccino","boundingBox":[322,1586,654.2,1601.1,650,1693,317.8,1678],"page":1,"confidence":0.923},"TotalPrice":{"type":"number","valueNumber":2.2,"text":"$2.20","boundingBox":[1107.7,1584,1263,1574,1268.3,1656,1113,1666],"page":1,"confidence":0.918}}},{"type":"object","valueObject":{"Quantity":{"type":"number","text":"1","boundingBox":[232,1834,286.6,1835,285,1921,230.4,1920],"page":1,"confidence":0.858},"Name":{"type":"string","valueString":"BACON
& EGGS","text":"BACON & EGGS","boundingBox":[308,1836,746,1841.4,745,1925.4,307,1920],"page":1,"confidence":0.916},"TotalPrice":{"type":"number","text":"$9.5","boundingBox":[1133.9,1955,1257,1952,1259.1,2036,1136,2039],"page":1,"confidence":0.916}}}]},"Subtotal":{"type":"number","valueNumber":11.7,"text":"11.70","boundingBox":[1146,2221,1297.3,2223,1296,2319,1144.7,2317],"page":1,"confidence":0.955},"Tax":{"type":"number","valueNumber":1.17,"text":"1.17","boundingBox":[1190,2359,1304,2359,1304,2456,1190,2456],"page":1,"confidence":0.979},"Tip":{"type":"number","valueNumber":1.63,"text":"1.63","boundingBox":[1094,2479,1267.7,2485,1264,2591,1090.3,2585],"page":1,"confidence":0.941},"Total":{"type":"number","valueNumber":14.5,"text":"$14.50","boundingBox":[1034.2,2617,1387.5,2638.2,1380,2763,1026.7,2741.8],"page":1,"confidence":0.985}}}]}}'
headers:
apim-request-id:
- 195addaa-7fcc-4053-bceb-5087740c57ed
content-type:
- application/json; charset=utf-8
date:
- Wed, 13 May 2020 16:13:45 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '378'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-ai-formrecognizer/1.0.0b3 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
method: GET
uri: https://westus.api.cognitive.microsoft.com/formrecognizer/v2.0-preview/custom/models?op=summary
response:
body:
string: '{"summary":{"count":0,"limit":5000,"lastUpdatedDateTime":"2020-05-13T16:13:47Z"}}'
headers:
apim-request-id:
- fa489acc-6458-4098-8379-b1f9389b3e1e
content-type:
- application/json; charset=utf-8
date:
- Wed, 13 May 2020 16:13:46 GMT
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
transfer-encoding:
- chunked
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '168'
status:
code: 200
message: OK
version: 1
Loading