Skip to content

Commit 29c4c7b

Browse files
authored
[text analytics] add logging param (#18729)
1 parent edb9881 commit 29c4c7b

File tree

36 files changed

+1302
-29
lines changed

36 files changed

+1302
-29
lines changed

sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
**New Features**
1212
- Added enums `EntityConditionality`, `EntityCertainty`, and `EntityAssociation`.
1313
- Added `AnalyzeSentimentAction` as a supported action type for `begin_analyze_batch_actions`.
14+
- Added kwarg `disable_service_logs`. If set to true, you opt-out of having your text input logged on the service side for troubleshooting.
1415

1516
## 5.1.0b6 (2021-03-09)
1617

@@ -114,7 +115,7 @@ used in conjunction with the Bing Entity Search API to fetch additional relevant
114115
- Removed `grapheme_offset` and `grapheme_length` from `CategorizedEntity`, `SentenceSentiment`, and `LinkedEntityMatch`
115116
- `TextDocumentStatistics` attribute `grapheme_count` has been renamed to `character_count`
116117

117-
## 1.0.0b5
118+
## 1.0.0b5
118119

119120
- This was a broken release
120121

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_models.py

Lines changed: 112 additions & 16 deletions
Large diffs are not rendered by default.

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) Microsoft Corporation.
44
# Licensed under the MIT License.
55
# ------------------------------------
6-
6+
import copy
77
from typing import ( # pylint: disable=unused-import
88
Union,
99
Optional,
@@ -157,6 +157,14 @@ def detect_language( # type: ignore
157157
See here for more info: https://aka.ms/text-analytics-model-versioning
158158
:keyword bool show_stats: If set to true, response will contain document
159159
level statistics in the `statistics` field of the document-level response.
160+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
161+
logged on the service side for troubleshooting. By default, Text Analytics logs your
162+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
163+
the Text Analytics natural language processing functions. Setting this parameter to true,
164+
disables input logging and may limit our ability to remediate issues that occur. Please see
165+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
166+
additional details, and Microsoft Responsible AI principles at
167+
https://www.microsoft.com/ai/responsible-ai.
160168
:return: The combined list of :class:`~azure.ai.textanalytics.DetectLanguageResult` and
161169
:class:`~azure.ai.textanalytics.DocumentError` in the order the original documents were
162170
passed in.
@@ -178,6 +186,9 @@ def detect_language( # type: ignore
178186
docs = _validate_input(documents, "country_hint", country_hint)
179187
model_version = kwargs.pop("model_version", None)
180188
show_stats = kwargs.pop("show_stats", False)
189+
disable_service_logs = kwargs.pop("disable_service_logs", None)
190+
if disable_service_logs is not None:
191+
kwargs['logging_opt_out'] = disable_service_logs
181192
try:
182193
return self._client.languages(
183194
documents=docs,
@@ -228,6 +239,14 @@ def recognize_entities( # type: ignore
228239
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
229240
you can also pass in `Utf16CodePoint` or TextElement_v8`. For additional information
230241
see https://aka.ms/text-analytics-offsets
242+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
243+
logged on the service side for troubleshooting. By default, Text Analytics logs your
244+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
245+
the Text Analytics natural language processing functions. Setting this parameter to true,
246+
disables input logging and may limit our ability to remediate issues that occur. Please see
247+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
248+
additional details, and Microsoft Responsible AI principles at
249+
https://www.microsoft.com/ai/responsible-ai.
231250
:return: The combined list of :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` and
232251
:class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
233252
were passed in.
@@ -256,6 +275,9 @@ def recognize_entities( # type: ignore
256275
)
257276
if string_index_type:
258277
kwargs.update({"string_index_type": string_index_type})
278+
disable_service_logs = kwargs.pop("disable_service_logs", None)
279+
if disable_service_logs is not None:
280+
kwargs['logging_opt_out'] = disable_service_logs
259281

260282
try:
261283
return self._client.entities_recognition_general(
@@ -316,6 +338,14 @@ def recognize_pii_entities( # type: ignore
316338
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
317339
you can also pass in `Utf16CodePoint` or `TextElement_v8`. For additional information
318340
see https://aka.ms/text-analytics-offsets
341+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
342+
logged on the service side for troubleshooting. By default, Text Analytics logs your
343+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
344+
the Text Analytics natural language processing functions. Setting this parameter to true,
345+
disables input logging and may limit our ability to remediate issues that occur. Please see
346+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
347+
additional details, and Microsoft Responsible AI principles at
348+
https://www.microsoft.com/ai/responsible-ai.
319349
:return: The combined list of :class:`~azure.ai.textanalytics.RecognizePiiEntitiesResult`
320350
and :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
321351
were passed in.
@@ -347,6 +377,9 @@ def recognize_pii_entities( # type: ignore
347377
)
348378
if string_index_type:
349379
kwargs.update({"string_index_type": string_index_type})
380+
disable_service_logs = kwargs.pop("disable_service_logs", None)
381+
if disable_service_logs is not None:
382+
kwargs['logging_opt_out'] = disable_service_logs
350383

351384
try:
352385
return self._client.entities_recognition_pii(
@@ -407,6 +440,14 @@ def recognize_linked_entities( # type: ignore
407440
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
408441
you can also pass in `Utf16CodePoint` or `TextElement_v8`. For additional information
409442
see https://aka.ms/text-analytics-offsets
443+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
444+
logged on the service side for troubleshooting. By default, Text Analytics logs your
445+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
446+
the Text Analytics natural language processing functions. Setting this parameter to true,
447+
disables input logging and may limit our ability to remediate issues that occur. Please see
448+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
449+
additional details, and Microsoft Responsible AI principles at
450+
https://www.microsoft.com/ai/responsible-ai.
410451
:return: The combined list of :class:`~azure.ai.textanalytics.RecognizeLinkedEntitiesResult`
411452
and :class:`~azure.ai.textanalytics.DocumentError` in the order the original documents
412453
were passed in.
@@ -428,6 +469,9 @@ def recognize_linked_entities( # type: ignore
428469
docs = _validate_input(documents, "language", language)
429470
model_version = kwargs.pop("model_version", None)
430471
show_stats = kwargs.pop("show_stats", False)
472+
disable_service_logs = kwargs.pop("disable_service_logs", None)
473+
if disable_service_logs is not None:
474+
kwargs['logging_opt_out'] = disable_service_logs
431475

432476
string_index_type = _check_string_index_type_arg(
433477
kwargs.pop("string_index_type", None),
@@ -503,6 +547,14 @@ def begin_analyze_healthcare_entities( # type: ignore
503547
:keyword int polling_interval: Waiting time between two polls for LRO operations
504548
if no Retry-After header is present. Defaults to 5 seconds.
505549
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
550+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
551+
logged on the service side for troubleshooting. By default, Text Analytics logs your
552+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
553+
the Text Analytics natural language processing functions. Setting this parameter to true,
554+
disables input logging and may limit our ability to remediate issues that occur. Please see
555+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
556+
additional details, and Microsoft Responsible AI principles at
557+
https://www.microsoft.com/ai/responsible-ai.
506558
:return: An instance of an AnalyzeHealthcareEntitiesLROPoller. Call `result()` on the this
507559
object to return a pageable of :class:`~azure.ai.textanalytics.AnalyzeHealthcareEntitiesResultItem`.
508560
:rtype:
@@ -529,22 +581,30 @@ def begin_analyze_healthcare_entities( # type: ignore
529581
string_index_type = kwargs.pop("string_index_type", self._string_index_type_default)
530582

531583
doc_id_order = [doc.get("id") for doc in docs]
584+
my_cls = kwargs.pop(
585+
"cls", partial(self._healthcare_result_callback, doc_id_order, show_stats=show_stats)
586+
)
587+
disable_service_logs = kwargs.pop("disable_service_logs", None)
588+
polling_kwargs = kwargs
589+
operation_kwargs = copy.copy(kwargs)
590+
if disable_service_logs is not None:
591+
operation_kwargs['logging_opt_out'] = disable_service_logs
532592

533593
try:
534594
return self._client.begin_health(
535595
docs,
536596
model_version=model_version,
537597
string_index_type=string_index_type,
538-
cls=kwargs.pop("cls", partial(self._healthcare_result_callback, doc_id_order, show_stats=show_stats)),
598+
cls=my_cls,
539599
polling=AnalyzeHealthcareEntitiesLROPollingMethod(
540600
text_analytics_client=self._client,
541601
timeout=polling_interval,
542602
lro_algorithms=[
543603
TextAnalyticsOperationResourcePolling(show_stats=show_stats)
544604
],
545-
**kwargs),
605+
**polling_kwargs),
546606
continuation_token=continuation_token,
547-
**kwargs
607+
**operation_kwargs
548608
)
549609

550610
except ValueError as error:
@@ -595,6 +655,14 @@ def extract_key_phrases( # type: ignore
595655
See here for more info: https://aka.ms/text-analytics-model-versioning
596656
:keyword bool show_stats: If set to true, response will contain document
597657
level statistics in the `statistics` field of the document-level response.
658+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
659+
logged on the service side for troubleshooting. By default, Text Analytics logs your
660+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
661+
the Text Analytics natural language processing functions. Setting this parameter to true,
662+
disables input logging and may limit our ability to remediate issues that occur. Please see
663+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
664+
additional details, and Microsoft Responsible AI principles at
665+
https://www.microsoft.com/ai/responsible-ai.
598666
:return: The combined list of :class:`~azure.ai.textanalytics.ExtractKeyPhrasesResult` and
599667
:class:`~azure.ai.textanalytics.DocumentError` in the order the original documents were
600668
passed in.
@@ -616,6 +684,10 @@ def extract_key_phrases( # type: ignore
616684
docs = _validate_input(documents, "language", language)
617685
model_version = kwargs.pop("model_version", None)
618686
show_stats = kwargs.pop("show_stats", False)
687+
disable_service_logs = kwargs.pop("disable_service_logs", None)
688+
if disable_service_logs is not None:
689+
kwargs['logging_opt_out'] = disable_service_logs
690+
619691
try:
620692
return self._client.key_phrases(
621693
documents=docs,
@@ -672,6 +744,14 @@ def analyze_sentiment( # type: ignore
672744
`UnicodeCodePoint`, the Python encoding, is the default. To override the Python default,
673745
you can also pass in `Utf16CodePoint` or `TextElement_v8`. For additional information
674746
see https://aka.ms/text-analytics-offsets
747+
:keyword bool disable_service_logs: If set to true, you opt-out of having your text input
748+
logged on the service side for troubleshooting. By default, Text Analytics logs your
749+
input text for 48 hours, solely to allow for troubleshooting issues in providing you with
750+
the Text Analytics natural language processing functions. Setting this parameter to true,
751+
disables input logging and may limit our ability to remediate issues that occur. Please see
752+
Cognitive Services Compliance and Privacy notes at https://aka.ms/cs-compliance for
753+
additional details, and Microsoft Responsible AI principles at
754+
https://www.microsoft.com/ai/responsible-ai.
675755
.. versionadded:: v3.1-preview
676756
The *show_opinion_mining* parameter.
677757
The *string_index_type* parameter.
@@ -697,6 +777,9 @@ def analyze_sentiment( # type: ignore
697777
model_version = kwargs.pop("model_version", None)
698778
show_stats = kwargs.pop("show_stats", False)
699779
show_opinion_mining = kwargs.pop("show_opinion_mining", None)
780+
disable_service_logs = kwargs.pop("disable_service_logs", None)
781+
if disable_service_logs is not None:
782+
kwargs['logging_opt_out'] = disable_service_logs
700783

701784
string_index_type = _check_string_index_type_arg(
702785
kwargs.pop("string_index_type", None),

0 commit comments

Comments
 (0)