1 package runtime
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "github.com/gofrs/uuid"
16 "net/http"
17 )
18
19
20 type PredictionClient struct {
21 BaseClient
22 }
23
24
25 func NewPredictionClient(endpoint string) PredictionClient {
26 return PredictionClient{New(endpoint)}
27 }
28
29
30
31
32
33
34
35
36
37 func (client PredictionClient) GetSlotPrediction(ctx context.Context, appID uuid.UUID, slotName string, predictionRequest PredictionRequest, verbose *bool, showAllIntents *bool, logParameter *bool) (result PredictionResponse, err error) {
38 if tracing.IsEnabled() {
39 ctx = tracing.StartSpan(ctx, fqdn+"/PredictionClient.GetSlotPrediction")
40 defer func() {
41 sc := -1
42 if result.Response.Response != nil {
43 sc = result.Response.Response.StatusCode
44 }
45 tracing.EndSpan(ctx, sc, err)
46 }()
47 }
48 if err := validation.Validate([]validation.Validation{
49 {TargetValue: predictionRequest,
50 Constraints: []validation.Constraint{{Target: "predictionRequest.Query", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
51 return result, validation.NewError("runtime.PredictionClient", "GetSlotPrediction", err.Error())
52 }
53
54 req, err := client.GetSlotPredictionPreparer(ctx, appID, slotName, predictionRequest, verbose, showAllIntents, logParameter)
55 if err != nil {
56 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetSlotPrediction", nil, "Failure preparing request")
57 return
58 }
59
60 resp, err := client.GetSlotPredictionSender(req)
61 if err != nil {
62 result.Response = autorest.Response{Response: resp}
63 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetSlotPrediction", resp, "Failure sending request")
64 return
65 }
66
67 result, err = client.GetSlotPredictionResponder(resp)
68 if err != nil {
69 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetSlotPrediction", resp, "Failure responding to request")
70 return
71 }
72
73 return
74 }
75
76
77 func (client PredictionClient) GetSlotPredictionPreparer(ctx context.Context, appID uuid.UUID, slotName string, predictionRequest PredictionRequest, verbose *bool, showAllIntents *bool, logParameter *bool) (*http.Request, error) {
78 urlParameters := map[string]interface{}{
79 "Endpoint": client.Endpoint,
80 }
81
82 pathParameters := map[string]interface{}{
83 "appId": autorest.Encode("path", appID),
84 "slotName": autorest.Encode("path", slotName),
85 }
86
87 queryParameters := map[string]interface{}{}
88 if verbose != nil {
89 queryParameters["verbose"] = autorest.Encode("query", *verbose)
90 }
91 if showAllIntents != nil {
92 queryParameters["show-all-intents"] = autorest.Encode("query", *showAllIntents)
93 }
94 if logParameter != nil {
95 queryParameters["log"] = autorest.Encode("query", *logParameter)
96 }
97
98 preparer := autorest.CreatePreparer(
99 autorest.AsContentType("application/json; charset=utf-8"),
100 autorest.AsPost(),
101 autorest.WithCustomBaseURL("{Endpoint}/luis/prediction/v3.0", urlParameters),
102 autorest.WithPathParameters("/apps/{appId}/slots/{slotName}/predict", pathParameters),
103 autorest.WithJSON(predictionRequest),
104 autorest.WithQueryParameters(queryParameters))
105 return preparer.Prepare((&http.Request{}).WithContext(ctx))
106 }
107
108
109
110 func (client PredictionClient) GetSlotPredictionSender(req *http.Request) (*http.Response, error) {
111 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
112 }
113
114
115
116 func (client PredictionClient) GetSlotPredictionResponder(resp *http.Response) (result PredictionResponse, err error) {
117 err = autorest.Respond(
118 resp,
119 azure.WithErrorUnlessStatusCode(http.StatusOK),
120 autorest.ByUnmarshallingJSON(&result),
121 autorest.ByClosing())
122 result.Response = autorest.Response{Response: resp}
123 return
124 }
125
126
127
128
129
130
131
132
133
134 func (client PredictionClient) GetVersionPrediction(ctx context.Context, appID uuid.UUID, versionID string, predictionRequest PredictionRequest, verbose *bool, showAllIntents *bool, logParameter *bool) (result PredictionResponse, err error) {
135 if tracing.IsEnabled() {
136 ctx = tracing.StartSpan(ctx, fqdn+"/PredictionClient.GetVersionPrediction")
137 defer func() {
138 sc := -1
139 if result.Response.Response != nil {
140 sc = result.Response.Response.StatusCode
141 }
142 tracing.EndSpan(ctx, sc, err)
143 }()
144 }
145 if err := validation.Validate([]validation.Validation{
146 {TargetValue: predictionRequest,
147 Constraints: []validation.Constraint{{Target: "predictionRequest.Query", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
148 return result, validation.NewError("runtime.PredictionClient", "GetVersionPrediction", err.Error())
149 }
150
151 req, err := client.GetVersionPredictionPreparer(ctx, appID, versionID, predictionRequest, verbose, showAllIntents, logParameter)
152 if err != nil {
153 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetVersionPrediction", nil, "Failure preparing request")
154 return
155 }
156
157 resp, err := client.GetVersionPredictionSender(req)
158 if err != nil {
159 result.Response = autorest.Response{Response: resp}
160 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetVersionPrediction", resp, "Failure sending request")
161 return
162 }
163
164 result, err = client.GetVersionPredictionResponder(resp)
165 if err != nil {
166 err = autorest.NewErrorWithError(err, "runtime.PredictionClient", "GetVersionPrediction", resp, "Failure responding to request")
167 return
168 }
169
170 return
171 }
172
173
174 func (client PredictionClient) GetVersionPredictionPreparer(ctx context.Context, appID uuid.UUID, versionID string, predictionRequest PredictionRequest, verbose *bool, showAllIntents *bool, logParameter *bool) (*http.Request, error) {
175 urlParameters := map[string]interface{}{
176 "Endpoint": client.Endpoint,
177 }
178
179 pathParameters := map[string]interface{}{
180 "appId": autorest.Encode("path", appID),
181 "versionId": autorest.Encode("path", versionID),
182 }
183
184 queryParameters := map[string]interface{}{}
185 if verbose != nil {
186 queryParameters["verbose"] = autorest.Encode("query", *verbose)
187 }
188 if showAllIntents != nil {
189 queryParameters["show-all-intents"] = autorest.Encode("query", *showAllIntents)
190 }
191 if logParameter != nil {
192 queryParameters["log"] = autorest.Encode("query", *logParameter)
193 }
194
195 preparer := autorest.CreatePreparer(
196 autorest.AsContentType("application/json; charset=utf-8"),
197 autorest.AsPost(),
198 autorest.WithCustomBaseURL("{Endpoint}/luis/prediction/v3.0", urlParameters),
199 autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/predict", pathParameters),
200 autorest.WithJSON(predictionRequest),
201 autorest.WithQueryParameters(queryParameters))
202 return preparer.Prepare((&http.Request{}).WithContext(ctx))
203 }
204
205
206
207 func (client PredictionClient) GetVersionPredictionSender(req *http.Request) (*http.Response, error) {
208 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
209 }
210
211
212
213 func (client PredictionClient) GetVersionPredictionResponder(resp *http.Response) (result PredictionResponse, err error) {
214 err = autorest.Respond(
215 resp,
216 azure.WithErrorUnlessStatusCode(http.StatusOK),
217 autorest.ByUnmarshallingJSON(&result),
218 autorest.ByClosing())
219 result.Response = autorest.Response{Response: resp}
220 return
221 }
222
View as plain text