From 2a40cb3bf4ccb951f336b5936e393dceb90e5880 Mon Sep 17 00:00:00 2001 From: iscai-msft <43154838+iscai-msft@users.noreply.github.com> Date: Wed, 2 Dec 2020 15:15:55 -0500 Subject: [PATCH] [text analytics] fix health cancellation samples (#15613) fixes #15611 --- .../ai/textanalytics/_text_analytics_client.py | 9 +++++++++ .../aio/_text_analytics_client_async.py | 9 +++++++++ .../sample_health_with_cancellation_async.py | 14 +++++++++----- .../samples/sample_health_with_cancellation.py | 12 ++++++++---- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py index dfac9153f72f..a6a02f2f0906 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py @@ -494,6 +494,15 @@ def begin_cancel_analyze_healthcare( # type: ignore :return: An instance of an LROPoller that returns None. :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError or NotImplementedError: + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_health_with_cancellation.py + :start-after: [START health_with_cancellation] + :end-before: [END health_with_cancellation] + :language: python + :dedent: 8 + :caption: Cancel an existing health operation. """ polling_interval = kwargs.pop("polling_interval", 5) initial_response = getattr(poller._polling_method, "_initial_response") # pylint: disable=protected-access diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py index ae37b37378c2..2206cac79001 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py @@ -647,6 +647,15 @@ async def begin_cancel_analyze_healthcare( # type: ignore :return: An instance of an LROPoller that returns None. :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError or TypeError or ValueError or NotImplementedError: + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_health_with_cancellation_async.py + :start-after: [START health_with_cancellation_async] + :end-before: [END health_with_cancellation_async] + :language: python + :dedent: 8 + :caption: Cancel an existing health operation. """ polling_interval = kwargs.pop("polling_interval", 5) # pylint: disable=protected-access diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_health_with_cancellation_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_health_with_cancellation_async.py index 059f4a153437..30da4e832504 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_health_with_cancellation_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_health_with_cancellation_async.py @@ -11,6 +11,10 @@ DESCRIPTION: This sample demonstrates how to cancel a Health job after it's been started. + Since the Health API is currently only available in a gated preview, you need + to have your subscription on the service's allow list. More information + here: https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-for-health?tabs=ner#request-access-to-the-public-preview. + USAGE: python sample_health_with_cancellation.py @@ -35,9 +39,9 @@ async def health_with_cancellation_async(self): key = os.environ["AZURE_TEXT_ANALYTICS_KEY"] text_analytics_client = TextAnalyticsClient( - endpoint=endpoint, + endpoint=endpoint, credential=AzureKeyCredential(key), - api_version="v3.2-preview.1") + api_version="v3.1-preview.3") documents = [ "RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | \ @@ -56,10 +60,10 @@ async def health_with_cancellation_async(self): ] async with text_analytics_client: - poller = await text_analytics_client.begin_health(documents) - cancellation_poller = await text_analytics_client.begin_cancel_health_operation(poller) + poller = await text_analytics_client.begin_analyze_healthcare(documents) + poller = await text_analytics_client.begin_cancel_analyze_healthcare(poller) - cancellation_poller.result() + await poller.wait() # [END health_with_cancellation_async] diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_health_with_cancellation.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_health_with_cancellation.py index 93b18948122f..4505625aafbf 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_health_with_cancellation.py +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_health_with_cancellation.py @@ -11,6 +11,9 @@ DESCRIPTION: This sample demonstrates how to cancel a Health job after it's been started. + Since the Health API is currently only available in a gated preview, you need + to have your subscription on the service's allow list. More information + here: https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-for-health?tabs=ner#request-access-to-the-public-preview. USAGE: python sample_health_with_cancellation.py @@ -35,9 +38,9 @@ def health_with_cancellation(self): key = os.environ["AZURE_TEXT_ANALYTICS_KEY"] text_analytics_client = TextAnalyticsClient( - endpoint=endpoint, + endpoint=endpoint, credential=AzureKeyCredential(key), - api_version="v3.2-preview.1") + api_version="v3.1-preview.3") documents = [ "RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | \ @@ -55,8 +58,9 @@ def health_with_cancellation(self): for revascularization with open heart surgery." ] - poller = text_analytics_client.begin_health(documents) - text_analytics_client.begin_cancel_health_operation(poller) + poller = text_analytics_client.begin_analyze_healthcare(documents) + text_analytics_client.begin_cancel_analyze_healthcare(poller) + poller.wait() # [END health_with_cancellation]