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

[text analytics] fix error response if pii entities is called from v3.0 client #13383

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ def recognize_pii_entities( # type: ignore
cls=kwargs.pop("cls", pii_entities_result),
**kwargs
)
except AttributeError as error:
if "'TextAnalyticsClient' object has no attribute 'entities_recognition_pii'" in str(error):
except NotImplementedError as error:
if "APIVersion v3.0 is not available" in str(error):
raise NotImplementedError(
"'recognize_pii_entities' endpoint is only available for API version v3.1-preview.1 and up"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ async def recognize_pii_entities( # type: ignore
cls=kwargs.pop("cls", pii_entities_result),
**kwargs
)
except AttributeError as error:
if "'TextAnalyticsClient' object has no attribute 'entities_recognition_pii'" in str(error):
except NotImplementedError as error:
if "APIVersion v3.0 is not available" in str(error):
raise NotImplementedError(
"'recognize_pii_entities' endpoint is only available for API version v3.1-preview.1 and up"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from azure.ai.textanalytics import (
TextAnalyticsClient,
TextDocumentInput,
VERSION
VERSION,
TextAnalyticsApiVersion,
)

# pre-apply the client_cls positional argument so it needn't be explicitly passed below
Expand Down Expand Up @@ -572,3 +573,11 @@ def callback(response):
language="en",
raw_response_hook=callback
)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_0})
def test_recognize_pii_entities_v3(self, client):
with pytest.raises(NotImplementedError) as excinfo:
client.recognize_pii_entities(["this should fail"])

assert "'recognize_pii_entities' endpoint is only available for API version v3.1-preview.1 and up" in str(excinfo.value)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from azure.ai.textanalytics import (
TextDocumentInput,
VERSION,
TextAnalyticsApiVersion,
)

# pre-apply the client_cls positional argument so it needn't be explicitly passed below
Expand Down Expand Up @@ -570,3 +571,11 @@ def callback(response):
language="en",
raw_response_hook=callback
)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_0})
async def test_recognize_pii_entities_v3(self, client):
with pytest.raises(NotImplementedError) as excinfo:
await client.recognize_pii_entities(["this should fail"])

assert "'recognize_pii_entities' endpoint is only available for API version v3.1-preview.1 and up" in str(excinfo.value)