Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
regenerate with v2.1-preview.3 and v2.1
  • Loading branch information
kristapratico committed May 2, 2021
commit d957589575d9cc9beb6ff85c3067379989a6d5ad
2 changes: 1 addition & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This table shows the relationship between SDK versions and supported API version
|SDK version|Supported API version of service
|-|-
|3.0.0 - Latest GA release (can be installed by removing the `--pre` flag)| 2.0
|3.1.0b4 - Latest release (beta)| 2.0, 2.1-preview.3
|3.1.0b5 - Latest release (beta)| 2.0, 2.1-preview.3, 2.1


#### Create a Form Recognizer resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class FormRecognizerApiVersion(str, Enum):
"""Form Recognizer API versions supported by this package"""

#: This is the default version
V2_1_PREVIEW = "2.1-preview.3"
V2_1 = "2.1"
V2_1_PREVIEW = "2.1-preview.3" # TODO what to do about this enum value?
V2_0 = "2.0"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, endpoint, credential, **kwargs):
self._endpoint = endpoint
self._credential = credential
self._api_version = kwargs.pop(
"api_version", FormRecognizerApiVersion.V2_1
"api_version", FormRecognizerApiVersion.V2_1_PREVIEW
)
validate_api_version(self._api_version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ def begin_recognize_receipts(self, receipt, **kwargs):
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if locale:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"locale": locale})
else:
raise ValueError(
"'locale' is only available for API version V2_1 and up"
"'locale' is only available for API version V2_1_PREVIEW and up"
)
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)
return self._client.begin_analyze_receipt_async( # type: ignore
file_stream=receipt,
Expand Down Expand Up @@ -198,20 +198,20 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs):
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if locale:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"locale": locale})
else:
raise ValueError(
"'locale' is only available for API version V2_1 and up"
"'locale' is only available for API version V2_1_PREVIEW and up"
)
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)
return self._client.begin_analyze_receipt_async( # type: ignore
file_stream={"source": receipt_url},
Expand Down Expand Up @@ -288,7 +288,7 @@ def begin_recognize_business_cards(self, business_card, **kwargs):
except ValueError as e:
if "begin_analyze_business_card_async" in str(e):
raise ValueError(
"Method 'begin_recognize_business_cards' is only available for API version V2_1 and up"
"Method 'begin_recognize_business_cards' is only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -338,7 +338,7 @@ def begin_recognize_business_cards_from_url(self, business_card_url, **kwargs):
if "begin_analyze_business_card_async" in str(e):
raise ValueError(
"Method 'begin_recognize_business_cards_from_url' is "
"only available for API version V2_1 and up"
"only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -406,7 +406,7 @@ def begin_recognize_id_documents(self, id_document, **kwargs):
except ValueError as e:
if "begin_analyze_id_document_async" in str(e):
raise ValueError(
"Method 'begin_recognize_id_documents' is only available for API version V2_1 and up"
"Method 'begin_recognize_id_documents' is only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -453,7 +453,7 @@ def begin_recognize_id_documents_from_url(self, id_document_url, **kwargs):
if "begin_analyze_id_document_async" in str(e):
raise ValueError(
"Method 'begin_recognize_id_documents_from_url' is "
"only available for API version V2_1 and up"
"only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -523,7 +523,7 @@ def begin_recognize_invoices(self, invoice, **kwargs):
except ValueError as e:
if "begin_analyze_invoice_async" in str(e):
raise ValueError(
"Method 'begin_recognize_invoices' is only available for API version V2_1 and up"
"Method 'begin_recognize_invoices' is only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -571,7 +571,7 @@ def begin_recognize_invoices_from_url(self, invoice_url, **kwargs):
if "begin_analyze_invoice_async" in str(e):
raise ValueError(
"Method 'begin_recognize_invoices_from_url' is "
"only available for API version V2_1 and up"
"only available for API version V2_1_PREVIEW and up"
)
raise e

Expand Down Expand Up @@ -644,27 +644,27 @@ def begin_recognize_content(self, form, **kwargs):
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)

if reading_order:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"reading_order": reading_order})
else:
raise ValueError(
"'reading_order' is only available for API version V2_1 and up"
"'reading_order' is only available for API version V2_1_PREVIEW and up"
)

if language:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"language": language})
else:
raise ValueError(
"'language' is only available for API version V2_1 and up"
"'language' is only available for API version V2_1_PREVIEW and up"
)

return self._client.begin_analyze_layout_async( # type: ignore
Expand Down Expand Up @@ -714,27 +714,27 @@ def begin_recognize_content_from_url(self, form_url, **kwargs):
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)

if reading_order:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"reading_order": reading_order})
else:
raise ValueError(
"'reading_order' is only available for API version V2_1 and up"
"'reading_order' is only available for API version V2_1_PREVIEW and up"
)

if language:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"language": language})
else:
raise ValueError(
"'language' is only available for API version V2_1 and up"
"'language' is only available for API version V2_1_PREVIEW and up"
)

return self._client.begin_analyze_layout_async( # type: ignore
Expand Down Expand Up @@ -817,11 +817,11 @@ def analyze_callback(
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)

return self._client.begin_analyze_with_custom_model( # type: ignore
Expand Down Expand Up @@ -886,11 +886,11 @@ def analyze_callback(
# FIXME: part of this code will be removed once autorest can handle diff mixin
# signatures across API versions
if pages:
if self._api_version == FormRecognizerApiVersion.V2_1:
if self._api_version in [FormRecognizerApiVersion.V2_1, FormRecognizerApiVersion.V2_1_PREVIEW]:
kwargs.update({"pages": pages})
else:
raise ValueError(
"'pages' is only available for API version V2_1 and up"
"'pages' is only available for API version V2_1_PREVIEW and up"
)

return self._client.begin_analyze_with_custom_model( # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument
model_name = kwargs.pop("model_name", None)
if model_name and self._api_version == "2.0":
raise ValueError(
"'model_name' is only available for API version V2_1 and up"
"'model_name' is only available for API version V2_1_PREVIEW and up"
)
continuation_token = kwargs.pop("continuation_token", None)
polling_interval = kwargs.pop(
Expand Down Expand Up @@ -492,7 +492,7 @@ def _compose_callback(
)
except ValueError:
raise ValueError(
"Method 'begin_create_composed_model' is only available for API version V2_1 and up"
"Method 'begin_create_composed_model' is only available for API version V2_1_PREVIEW and up"
)

def get_form_recognizer_client(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ class FormRecognizerClient(FormRecognizerClientOperationsMixin, MultiApiClientMi
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
"""

DEFAULT_API_VERSION = '2.1'
DEFAULT_API_VERSION = '2.1-preview.3'
_PROFILE_TAG = "azure.ai.formrecognizer.FormRecognizerClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'train_custom_model_async': '2.0',
}},
_PROFILE_TAG + " latest"
)
Expand All @@ -77,6 +76,8 @@ def __init__(
base_url = '{endpoint}/formrecognizer/v2.0'
elif api_version == '2.1':
base_url = '{endpoint}/formrecognizer/v2.1'
elif api_version == '2.1-preview.3':
base_url = '{endpoint}/formrecognizer/v2.1-preview.3'
else:
raise ValueError("API version {} is not available".format(api_version))
self._config = FormRecognizerClientConfiguration(credential, endpoint, **kwargs)
Expand All @@ -96,13 +97,17 @@ def models(cls, api_version=DEFAULT_API_VERSION):

* 2.0: :mod:`v2_0.models<azure.ai.formrecognizer.v2_0.models>`
* 2.1: :mod:`v2_1.models<azure.ai.formrecognizer.v2_1.models>`
* 2.1-preview.3: :mod:`v2_1_preview_3.models<azure.ai.formrecognizer.v2_1_preview_3.models>`
"""
if api_version == '2.0':
from .v2_0 import models
return models
elif api_version == '2.1':
from .v2_1 import models
return models
elif api_version == '2.1-preview.3':
from .v2_1_preview_3 import models
return models
raise ValueError("API version {} is not available".format(api_version))

def close(self):
Expand Down
Loading