Skip to content

Commit

Permalink
[text analytics] fix health cancellation samples (#15613)
Browse files Browse the repository at this point in the history
fixes #15611
  • Loading branch information
iscai-msft authored Dec 2, 2020
1 parent a18c3d2 commit 2a40cb3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 | \
Expand All @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 | \
Expand All @@ -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]

Expand Down

0 comments on commit 2a40cb3

Please sign in to comment.