Skip to content

Commit 59d7277

Browse files
committed
chore(examples): Add IAM authentication to examples
1 parent 716a504 commit 59d7277

10 files changed

Lines changed: 88 additions & 1 deletion

examples/assistant_v1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
assistant = AssistantV1(
66
username='YOUR SERVICE USERNAME',
77
password='YOUR SERVICE PASSWORD',
8+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
9+
# url='https://gateway.watsonplatform.net/assistant/api',
810
version='2017-04-21')
911

12+
## If service instance provides API key authentication
13+
# assistant = AssistantV1(
14+
# version='2017-04-21',
15+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
16+
# url='https://gateway.watsonplatform.net/assistant/api',
17+
# iam_api_key='your_api_key')
18+
1019
#########################
1120
# Workspaces
1221
#########################

examples/conversation_v1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
conversation = ConversationV1(
66
username='YOUR SERVICE USERNAME',
77
password='YOUR SERVICE PASSWORD',
8+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
9+
# url='https://gateway.watsonplatform.net/conversation/api',
810
version='2018-02-16')
911

12+
## If service instance provides API key authentication
13+
# conversation = ConversationV1(
14+
# version='2018-02-16',
15+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
16+
# url='https://gateway.watsonplatform.net/conversation/api',
17+
# iam_api_key='your_api_key')
18+
19+
1020
# When you send multiple requests for the same conversation, include the
1121
# context object from the previous response.
1222
# response = conversation.message(workspace_id=workspace_id, message_input={

examples/discovery_v1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55

66
discovery = DiscoveryV1(
77
version='2017-10-16',
8+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
9+
# url='https://gateway.watsonplatform.net/discovery/api',
810
username='YOUR SERVICE USERNAME',
911
password='YOUR SERVICE PASSWORD')
1012

13+
## If service instance provides API key authentication
14+
# discovery = DiscoveryV1(
15+
# version='2017-10-16',
16+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
17+
# url='https://gateway.watsonplatform.net/discovery/api',
18+
# iam_api_key='your_api_key')
19+
1120
environments = discovery.list_environments()
1221
print(json.dumps(environments, indent=2))
1322

examples/natural_language_classifier_v1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
from watson_developer_cloud import NaturalLanguageClassifierV1
77

88
natural_language_classifier = NaturalLanguageClassifierV1(
9+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
10+
# url='https://gateway.watsonplatform.net/natural-language-classifier/api',
911
username='YOUR SERVICE USERNAME',
1012
password='YOUR SERVICE PASSWORD')
1113

14+
## If service instance provides API key authentication
15+
# natural_language_classifier = NaturalLanguageClassifierV1(
16+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
17+
# url='https://gateway.watsonplatform.net/natural-language-classifier/api',
18+
# iam_api_key='your_api_key')
19+
1220
classifiers = natural_language_classifier.list_classifiers()
1321
print(json.dumps(classifiers, indent=2))
1422

examples/natural_language_understanding_v1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66

77
natural_language_understanding = NaturalLanguageUnderstandingV1(
88
version='2017-02-27',
9+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
10+
# url='https://gateway.watsonplatform.net/natural-language-understanding/api',
911
username='YOUR SERVICE USERNAME',
1012
password='YOUR SERVICE PASSWORD')
1113

14+
## If service instance provides API key authentication
15+
# natural_language_understanding = NaturalLanguageUnderstandingV1(
16+
# version='2017-02-27',
17+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
18+
# url='https://gateway.watsonplatform.net/natural-language-understanding/api',
19+
# iam_api_key='your_api_key')
20+
1221
response = natural_language_understanding.analyze(
1322
text='Bruce Banner is the Hulk and Bruce Wayne is BATMAN! '
1423
'Superman fears not Banner, but Wayne.',

examples/personality_insights_v3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
99

1010
personality_insights = PersonalityInsightsV3(
1111
version='2016-10-20',
12+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
13+
# url='https://gateway.watsonplatform.net/personality-insights/api',
1214
username='YOUR SERVICE USERNAME',
1315
password='YOUR SERVICE PASSWORD')
1416

17+
## If service instance provides API key authentication
18+
# personality_insights = PersonalityInsightsV3(
19+
# version='2016-10-20',
20+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
21+
# url='https://gateway.watsonplatform.net/personality-insights/api',
22+
# iam_api_key='your_api_key')
23+
1524
with open(join(dirname(__file__), '../resources/personality-v3.json')) as \
1625
profile_json:
1726
profile = personality_insights.profile(

examples/speech_to_text_v1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
password='YOUR SERVICE PASSWORD',
1010
url='https://stream.watsonplatform.net/speech-to-text/api')
1111

12+
## If service instance provides API key authentication
13+
# speech_to_text = SpeechToTextV1(
14+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
15+
# url='https://stream.watsonplatform.net/speech-to-text/api',
16+
# iam_api_key='your_api_key')
17+
1218
print(json.dumps(speech_to_text.list_models(), indent=2))
1319

1420
print(json.dumps(speech_to_text.get_model('en-US_BroadbandModel'), indent=2))

examples/text_to_speech_v1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
from watson_developer_cloud import TextToSpeechV1
66

77
text_to_speech = TextToSpeechV1(
8+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
9+
# url='https://stream.watsonplatform.net/text-to-speech/api,
810
username='YOUR SERVICE USERNAME',
911
password='YOUR SERVICE PASSWORD')
1012

13+
## If service instance provides API key authentication
14+
# text_to_speech = TextToSpeechV1(
15+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
16+
# url='https://stream.watsonplatform.net/text-to-speech/api',
17+
# iam_api_key='your_api_key')
18+
1119
print(json.dumps(text_to_speech.list_voices(), indent=2))
1220

1321
with open(join(dirname(__file__), '../resources/output.wav'),

examples/tone_analyzer_v3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
from watson_developer_cloud.tone_analyzer_v3 import ToneInput
66

77
tone_analyzer = ToneAnalyzerV3(
8+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
9+
# url='https://gateway.watsonplatform.net/tone-analyzer/api',
810
username='YOUR SERVICE USERNAME',
911
password='YOUR SERVICE PASSWORD',
1012
version='2017-09-26')
1113

14+
## If service instance provides API key authentication
15+
# tone_analyzer = ToneAnalyzerV3(
16+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
17+
# url='https://gateway.watsonplatform.net/tone-analyzer/api',
18+
# version='2017-09-26',
19+
# iam_api_key='your_api_key')
20+
1221
print("\ntone_chat() example 1:\n")
1322
utterances = [{'text': 'I am very happy.', 'user': 'glenn'},
1423
{'text': 'It is a good day.', 'user': 'glenn'}]

examples/visual_recognition_v3.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
test_url = 'https://www.ibm.com/ibm/ginni/images' \
77
'/ginni_bio_780x981_v4_03162016.jpg'
88

9-
visual_recognition = VisualRecognitionV3('2016-05-20', api_key='YOUR API KEY')
9+
visual_recognition = VisualRecognitionV3('2016-05-20',
10+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
11+
# url='https://gateway.watsonplatform.net/visual-recognition/api',
12+
api_key='YOUR API KEY')
13+
14+
## If service instance provides IAM API key authentication
15+
# visual_recognition = VisualRecognitionV3(
16+
# '2016-05-20',
17+
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
18+
# url='https://gateway.watsonplatform.net/visual-recognition/api',
19+
# iam_api_key='your_api_key')
1020

1121
# with open(join(dirname(__file__), '../resources/cars.zip'), 'rb') as cars, \
1222
# open(join(dirname(__file__), '../resources/trucks.zip'), 'rb') as

0 commit comments

Comments
 (0)