Skip to content

Commit 5d04dfe

Browse files
authored
move environment variable setting into sample functions (Azure#11746)
1 parent c4beba5 commit 5d04dfe

14 files changed

+68
-51
lines changed

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_alternative_document_input_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727

2828
class AlternativeDocumentInputSampleAsync(object):
2929

30-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
31-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
32-
3330
async def alternative_document_input(self):
3431
from azure.core.credentials import AzureKeyCredential
3532
from azure.ai.textanalytics.aio import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
33+
34+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
35+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
36+
37+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3738

3839
documents = [
3940
{"id": "0", "language": "en", "text": "I had the best day of my life."},

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_analyze_sentiment_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727

2828
class AnalyzeSentimentSampleAsync(object):
2929

30-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
31-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
32-
3330
async def analyze_sentiment_async(self):
3431
# [START batch_analyze_sentiment_async]
3532
from azure.core.credentials import AzureKeyCredential
3633
from azure.ai.textanalytics.aio import TextAnalyticsClient
37-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
34+
35+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
36+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
37+
38+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3839
documents = [
3940
"I had the best day of my life.",
4041
"This was a waste of my time. The speaker put me to sleep.",

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_detect_language_async.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ async def detect_language_async(self):
3434
# [START batch_detect_language_async]
3535
from azure.core.credentials import AzureKeyCredential
3636
from azure.ai.textanalytics.aio import TextAnalyticsClient
37-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
37+
38+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
39+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
40+
41+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3842
documents = [
3943
"This document is written in English.",
4044
"Este es un document escrito en Español.",

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_extract_key_phrases_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
class ExtractKeyPhrasesSampleAsync(object):
2828

29-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
30-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
31-
3229
async def extract_key_phrases_async(self):
3330
# [START batch_extract_key_phrases_async]
3431
from azure.core.credentials import AzureKeyCredential
3532
from azure.ai.textanalytics.aio import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
33+
34+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
35+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
36+
37+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3738
documents = [
3839
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
3940
"I need to take my cat to the veterinarian.",

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_get_detailed_diagnostics_information_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030

3131
class GetDetailedDiagnosticsInformationSampleAsync(object):
3232

33-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
34-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
35-
3633
async def get_detailed_diagnostics_information_async(self):
3734
from azure.core.credentials import AzureKeyCredential
3835
from azure.ai.textanalytics.aio import TextAnalyticsClient
3936

37+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
38+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
39+
4040
# This client will log detailed information about its HTTP sessions, at DEBUG level
41-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key), logging_enable=True)
41+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key), logging_enable=True)
4242

4343
documents = [
4444
"I had the best day of my life.",

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_entities_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
class RecognizeEntitiesSampleAsync(object):
2828

29-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
30-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
31-
3229
async def recognize_entities_async(self):
3330
# [START batch_recognize_entities_async]
3431
from azure.core.credentials import AzureKeyCredential
3532
from azure.ai.textanalytics.aio import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
33+
34+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
35+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
36+
37+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3738
documents = [
3839
"Microsoft was founded by Bill Gates and Paul Allen.",
3940
"I had a wonderful trip to Seattle last week.",

sdk/textanalytics/azure-ai-textanalytics/samples/async_samples/sample_recognize_linked_entities_async.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828

2929
class RecognizeLinkedEntitiesSampleAsync(object):
3030

31-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
32-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
33-
3431
async def recognize_linked_entities_async(self):
3532
# [START batch_recognize_linked_entities_async]
3633
from azure.core.credentials import AzureKeyCredential
3734
from azure.ai.textanalytics.aio import TextAnalyticsClient
38-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
35+
36+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
37+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
38+
39+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3940
documents = [
4041
"Microsoft moved its headquarters to Bellevue, Washington in January 1979.",
4142
"Steve Ballmer stepped down as CEO of Microsoft and was succeeded by Satya Nadella.",

sdk/textanalytics/azure-ai-textanalytics/samples/sample_alternative_document_input.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727
_LOGGER = logging.getLogger(__name__)
2828

2929
class AlternativeDocumentInputSample(object):
30-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
31-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
3230

3331
def alternative_document_input(self):
3432
from azure.core.credentials import AzureKeyCredential
3533
from azure.ai.textanalytics import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
34+
35+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
36+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
37+
38+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3739

3840
documents = [
3941
{"id": "0", "language": "en", "text": "I had the best day of my life."},

sdk/textanalytics/azure-ai-textanalytics/samples/sample_analyze_sentiment.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
class AnalyzeSentimentSample(object):
2828

29-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
30-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
31-
3229
def analyze_sentiment(self):
3330
# [START batch_analyze_sentiment]
3431
from azure.core.credentials import AzureKeyCredential
3532
from azure.ai.textanalytics import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
33+
34+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
35+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
36+
37+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3738
documents = [
3839
"I had the best day of my life.",
3940
"This was a waste of my time. The speaker put me to sleep.",

sdk/textanalytics/azure-ai-textanalytics/samples/sample_detect_language.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
class DetectLanguageSample(object):
2828

29-
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
30-
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
31-
3229
def detect_language(self):
3330
# [START batch_detect_language]
3431
from azure.core.credentials import AzureKeyCredential
3532
from azure.ai.textanalytics import TextAnalyticsClient
36-
text_analytics_client = TextAnalyticsClient(endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
33+
34+
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
35+
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
36+
37+
text_analytics_client = TextAnalyticsClient(endpoint=endpoint, credential=AzureKeyCredential(key))
3738
documents = [
3839
"This document is written in English.",
3940
"Este es un document escrito en Español.",

0 commit comments

Comments
 (0)