-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload_entities_intents_df.py
119 lines (114 loc) · 2.48 KB
/
upload_entities_intents_df.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import json
import requests
from time import sleep
# Upload entity types out of a list
def dialogflow_client_put_entity_types(all_entity_types):
for entity_type in all_entity_types:
entity_type_json = json.dumps(entity_type)
res = requests.put(
'https://api.api.ai/v1/entities?v=20170712',
headers = {"Authorization": "bearer 2cb9423f7501441d987806f014384779",
"Content-Type": "application/json; charset=utf-8"},
data = entity_type_json)
print(res.status_code)
if not res.status_code == 200:
print(entity_type_json)
sleep(1)
# Upload intents out of a list
def dialogflow_client_put_intents(all_intents):
for intent in all_intents:
intent_json = json.dumps(intent)
res = requests.post(
'https://api.api.ai/v1/intents?v=20170712',
headers={"Authorization": "bearer 2cb9423f7501441d987806f014384779",
"Content-Type": "application/json; charset=utf-8" },
data=intent_json)
if not res.status_code == 200:
print(intent_json)
print(res.status_code)
sleep(1)
# Data
entity_types = [
{
"name": "enable",
"entries": [
{
"synonyms": [],
"value": "enable"
}, {
"synonyms": [],
"value": "switch on"
}, {
"synonyms": [],
"value": "activate"
}
]
}, {
"name": "device",
"entries": [
{
"synonyms": [],
"value": "alarm"
}, {
"synonyms": [],
"value": "TV"
}, {
"synonyms": [],
"value": "lights"
}
]
}
]
intents = [
{
"name": "EnableDevice",
"auto": True,
"templates": [
"@enable @device",
"@device",
"@enable the @device",
"@enable the @device, please"
],
"userSays": [],
"contexts": [],
"responses": [
{
"messages": [
{
"type": 0,
"speech": [
"Ok, I will $enable the $device!",
"Ok, I will turn on the $device!"
],
"lang": "en"
}
],
"affectedContexts": [],
"speech": [],
"action": "EnableDevice",
"parameters": [
{
"prompts": [
"what should I $enable?"
],
"name": "device",
"required": True,
"dataType": "@device",
"value": "$device"
},
{
"name": "enable",
"required": False,
"dataType": "@enable",
"value": "$enable"
}
],
"resetContexts": True
}
],
"priority": 500000
}
]
# Upload entities and intents
dialogflow_client_put_entity_types(entity_types)
dialogflow_client_put_intents(intents)