forked from watson-developer-cloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant_v2.py
More file actions
41 lines (34 loc) · 1.24 KB
/
assistant_v2.py
File metadata and controls
41 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import print_function
import json
from watson_developer_cloud import AssistantV2
# If service instance provides API key authentication
# assistant = AssistantV2(
# version='2018-09-20',
# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
# url='https://gateway.watsonplatform.net/assistant/api',
# iam_apikey='iam_apikey')
assistant = AssistantV2(
username='YOUR SERVICE USERNAME',
password='YOUR SERVICE PASSWORD',
## url is optional, and defaults to the URL below. Use the correct URL for your region.
url='https://gateway.watsonplatform.net/assistant/api',
version='2018-09-20')
#########################
# Sessions
#########################
session = assistant.create_session("<YOUR ASSISTANT ID>").get_result()
print(json.dumps(session, indent=2))
assistant.delete_session("<YOUR ASSISTANT ID>", "<YOUR SESSION ID>").get_result()
#########################
# Message
#########################
message = assistant.message(
"<YOUR ASSISTANT ID>",
"<YOUR SESSION ID>",
input={'text': 'What\'s the weather like?'},
context={
'metadata': {
'deployment': 'myDeployment'
}
}).get_result()
print(json.dumps(message, indent=2))