-
Notifications
You must be signed in to change notification settings - Fork 509
/
model.py
148 lines (126 loc) · 4.17 KB
/
model.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
########### Python 3.6 #############
#
# This quickstart shows how to add utterances to a LUIS model using the REST APIs.
#
import requests
try:
##########
# Values to modify.
# YOUR-APP-ID: The App ID GUID found on the www.luis.ai Application Settings page.
appId = "PASTE_YOUR_LUIS_APP_ID_HERE"
# YOUR-AUTHORING-KEY: Your LUIS authoring key, 32 character value.
authoring_key = "PASTE_YOUR_LUIS_AUTHORING_SUBSCRIPTION_KEY_HERE"
# YOUR-AUTHORING-ENDPOINT: Replace this with your authoring key endpoint.
# For example, "https://your-resource-name.cognitiveservices.azure.com/"
authoring_endpoint = "PASTE_YOUR_LUIS_AUTHORING_ENDPOINT_HERE"
# The version number of your LUIS app
app_version = "0.1"
##########
# The headers to use in this REST call.
headers = {'Ocp-Apim-Subscription-Key': authoring_key}
# The URL parameters to use in this REST call.
params ={
#'timezoneOffset': '0',
#'verbose': 'true',
#'show-all-intents': 'true',
#'spellCheck': 'false',
#'staging': 'false'
}
# List of example utterances to send to the LUIS app.
data = """[
{
'text': 'order a pizza',
'intentName': 'ModifyOrder',
'entityLabels': [
{
'entityName': 'Order',
'startCharIndex': 6,
'endCharIndex': 12
}
]
},
{
'text': 'order a large pepperoni pizza',
'intentName': 'ModifyOrder',
'entityLabels': [
{
'entityName': 'Order',
'startCharIndex': 6,
'endCharIndex': 28
},
{
'entityName': 'FullPizzaWithModifiers',
'startCharIndex': 6,
'endCharIndex': 28
},
{
'entityName': 'PizzaType',
'startCharIndex': 14,
'endCharIndex': 28
},
{
'entityName': 'Size',
'startCharIndex': 8,
'endCharIndex': 12
}
]
},
{
'text': 'I want two large pepperoni pizzas on thin crust',
'intentName': 'ModifyOrder',
'entityLabels': [
{
'entityName': 'Order',
'startCharIndex': 7,
'endCharIndex': 46
},
{
'entityName': 'FullPizzaWithModifiers',
'startCharIndex': 7,
'endCharIndex': 46
},
{
'entityName': 'PizzaType',
'startCharIndex': 17,
'endCharIndex': 32
},
{
'entityName': 'Size',
'startCharIndex': 11,
'endCharIndex': 15
},
{
'entityName': 'Quantity',
'startCharIndex': 7,
'endCharIndex': 9
},
{
'entityName': 'Crust',
'startCharIndex': 37,
'endCharIndex': 46
}
]
}
]
"""
# Make the REST call to POST the list of example utterances.
response = requests.post(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/examples',
headers=headers, params=params, data=data)
# Display the results on the console.
print('Add the list of utterances:')
print(response.json())
# Make the REST call to initiate a training session.
response = requests.post(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/train',
headers=headers, params=params, data=None)
# Display the results on the console.
print('Request training:')
print(response.json())
# Make the REST call to request the status of training.
response = requests.get(f'{authoring_endpoint}luis/authoring/v3.0-preview/apps/{appId}/versions/{app_version}/train',
headers=headers, params=params, data=None)
# Display the results on the console.
print('Request training status:')
print(response.json())
except Exception as e:
# Display the error string.
print(f'{e}')