diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md index ba0f79d79369..26a57ffd32b4 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/README.md @@ -60,7 +60,7 @@ what you can do with the Azure Text Analytics client library. |**Advanced Sample File Name**|**Description**| |----------------|-------------| -|[sample_get_detailed_diagnostics_information.py][get_detailed_diagnostics_information] and [sample_get_detailed_diagnostics_information_async.py][get_detailed_diagnostics_information_async]|Get the request batch statistics, model version, and raw response through a callback| +|[sample_get_detailed_diagnostics_information.py][get_detailed_diagnostics_information] and [sample_get_detailed_diagnostics_information_async.py][get_detailed_diagnostics_information_async]|Get the request batch statistics, model version, and raw response in JSON format through a callback| [azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity [sample_authentication]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/textanalytics/azure-ai-textanalytics/samples/sample_authentication.py diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py index 6e5ff2ca6528..5433218a3b69 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to retrieve batch statistics, the - model version used, and the raw response returned from the service. + model version used, and the raw response in JSON format returned from the service. USAGE: python sample_get_detailed_diagnostics_information_async.py @@ -24,6 +24,7 @@ import os import asyncio import logging +import json _LOGGER = logging.getLogger(__name__) @@ -35,7 +36,9 @@ class GetDetailedDiagnosticsInformationSampleAsync(object): async def get_detailed_diagnostics_information_async(self): from azure.core.credentials import AzureKeyCredential from azure.ai.textanalytics.aio import TextAnalyticsClient - text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key)) + + # This client will log detailed information about its HTTP sessions, at DEBUG level + text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key), logging_enable=True) documents = [ "I had the best day of my life.", @@ -44,13 +47,16 @@ async def get_detailed_diagnostics_information_async(self): "L'hôtel n'était pas très confortable. L'éclairage était trop sombre." ] + json_responses = [] + def callback(resp): - _LOGGER.info("document_count: {}".format(resp.statistics["document_count"])) - _LOGGER.info("valid_document_count: {}".format(resp.statistics["valid_document_count"])) - _LOGGER.info("erroneous_document_count: {}".format(resp.statistics["erroneous_document_count"])) - _LOGGER.info("transaction_count: {}".format(resp.statistics["transaction_count"])) - _LOGGER.info("model_version: {}".format(resp.model_version)) - _LOGGER.info("raw_response: {}".format(resp.raw_response)) + _LOGGER.debug("document_count: {}".format(resp.statistics["document_count"])) + _LOGGER.debug("valid_document_count: {}".format(resp.statistics["valid_document_count"])) + _LOGGER.debug("erroneous_document_count: {}".format(resp.statistics["erroneous_document_count"])) + _LOGGER.debug("transaction_count: {}".format(resp.statistics["transaction_count"])) + _LOGGER.debug("model_version: {}".format(resp.model_version)) + json_response = json.dumps(resp.raw_response) + json_responses.append(json_response) async with text_analytics_client: result = await text_analytics_client.analyze_sentiment( @@ -60,6 +66,8 @@ def callback(resp): raw_response_hook=callback ) + _LOGGER.debug("json response: {}".format(json_responses[0])) + async def main(): sample = GetDetailedDiagnosticsInformationSampleAsync() diff --git a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_get_detailed_diagnostics_information.py b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_get_detailed_diagnostics_information.py index ea561c7066d5..9a1fa655911b 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/samples/sample_get_detailed_diagnostics_information.py +++ b/sdk/textanalytics/azure-ai-textanalytics/samples/sample_get_detailed_diagnostics_information.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to retrieve batch statistics, the - model version used, and the raw response returned from the service. + model version used, and the raw response in JSON format returned from the service. USAGE: python sample_get_detailed_diagnostics_information.py @@ -23,6 +23,7 @@ import os import logging +import json _LOGGER = logging.getLogger(__name__) @@ -33,7 +34,9 @@ class GetDetailedDiagnosticsInformationSample(object): def get_detailed_diagnostics_information(self): from azure.core.credentials import AzureKeyCredential from azure.ai.textanalytics import TextAnalyticsClient - text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key)) + + # This client will log detailed information about its HTTP sessions, at DEBUG level + text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key), logging_enable=True) documents = [ "I had the best day of my life.", @@ -42,13 +45,16 @@ def get_detailed_diagnostics_information(self): "L'hôtel n'était pas très confortable. L'éclairage était trop sombre." ] + json_responses = [] + def callback(resp): - _LOGGER.info("document_count: {}".format(resp.statistics["document_count"])) - _LOGGER.info("valid_document_count: {}".format(resp.statistics["valid_document_count"])) - _LOGGER.info("erroneous_document_count: {}".format(resp.statistics["erroneous_document_count"])) - _LOGGER.info("transaction_count: {}".format(resp.statistics["transaction_count"])) - _LOGGER.info("model_version: {}".format(resp.model_version)) - _LOGGER.info("raw_response: {}".format(resp.raw_response)) + _LOGGER.debug("document_count: {}".format(resp.statistics["document_count"])) + _LOGGER.debug("valid_document_count: {}".format(resp.statistics["valid_document_count"])) + _LOGGER.debug("erroneous_document_count: {}".format(resp.statistics["erroneous_document_count"])) + _LOGGER.debug("transaction_count: {}".format(resp.statistics["transaction_count"])) + _LOGGER.debug("model_version: {}".format(resp.model_version)) + json_response = json.dumps(resp.raw_response) + json_responses.append(json_response) result = text_analytics_client.analyze_sentiment( documents, @@ -57,6 +63,8 @@ def callback(resp): raw_response_hook=callback ) + _LOGGER.debug("json response: {}".format(json_responses[0])) + if __name__ == '__main__': sample = GetDetailedDiagnosticsInformationSample()