-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[text analytics] Add how to get json response to sample #11102
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.", | ||
|
|
@@ -45,12 +48,14 @@ async def get_detailed_diagnostics_information_async(self): | |
| ] | ||
|
|
||
| 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)) | ||
| _LOGGER.debug("raw_response: {}".format(resp.raw_response)) | ||
| 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 +65,9 @@ def callback(resp): | |
| raw_response_hook=callback | ||
| ) | ||
|
|
||
| for idx, json_responses in enumerate(json_respones): | ||
|
||
| _LOGGER.debug("json response for document #{}: {}".format(resp.raw_response, idx)) | ||
|
|
||
|
|
||
| async def main(): | ||
| sample = GetDetailedDiagnosticsInformationSampleAsync() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,17 @@ 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)) | ||
| _LOGGER.debug("raw_response: {}".format(resp.raw_response)) | ||
|
||
| json_response = json.dumps(resp.raw_response) | ||
| json_responses.append(json_response) | ||
|
|
||
| result = text_analytics_client.analyze_sentiment( | ||
| documents, | ||
|
|
@@ -57,6 +64,9 @@ def callback(resp): | |
| raw_response_hook=callback | ||
| ) | ||
|
|
||
| for idx, json_responses in enumerate(json_respones): | ||
| _LOGGER.debug("json response for document #{}: {}".format(resp.raw_response, idx)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| sample = GetDetailedDiagnosticsInformationSample() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where this list is created