-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresponse.go
117 lines (105 loc) · 3.01 KB
/
response.go
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
package luis
import (
"encoding/json"
"log"
"time"
)
//AppInfo : Display app detail info
type AppInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Description interface{} `json:"description"`
Culture string `json:"culture"`
UsageScenario string `json:"usageScenario"`
Domain string `json:"domain"`
VersionsCount int `json:"versionsCount"`
CreatedDateTime time.Time `json:"createdDateTime"`
Endpoints struct {
PRODUCTION struct {
VersionID string `json:"versionId"`
IsStaging bool `json:"isStaging"`
EndpointURL string `json:"endpointUrl"`
AssignedEndpointKey string `json:"assignedEndpointKey"`
PublishedDateTime time.Time `json:"publishedDateTime"`
} `json:"PRODUCTION"`
} `json:"endpoints"`
EndpointHitsCount int `json:"endpointHitsCount"`
}
//IntentListResponse :
type IntentListResponse []struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}
//NewAppInfo :
func NewAppInfo(raw []byte) *AppInfo {
ret := &AppInfo{}
err := json.Unmarshal(raw, &ret)
if err != nil {
log.Println("json unmarshal err:", err)
return ret
}
return ret
}
//NewIntentListResponse :
func NewIntentListResponse(raw []byte) *IntentListResponse {
ret := &IntentListResponse{}
err := json.Unmarshal(raw, &ret)
if err != nil {
log.Println("json unmarshal err:", err)
return ret
}
return ret
}
//ErrorResponse :
//Storage all HTTP response include http.response code and error code
type ErrorResponse struct {
ErrorCode int
Err error
}
//ActionChannelsResponse :
type ActionChannelsResponse []struct {
Name string `json:"Name"`
Version int `json:"Version"`
SupportURI string `json:"SupportUri"`
Actions []struct {
Name string `json:"Name"`
Parameters []struct {
Name string `json:"Name"`
DataType string `json:"DataType"`
PlaceHolderText string `json:"PlaceHolderText"`
Required bool `json:"Required"`
} `json:"Parameters"`
SupportedAuthenticationTypes []int `json:"SupportedAuthenticationTypes"`
} `json:"Actions"`
}
type IntentsResultType struct {
Name string `json:"Name"`
Label interface{} `json:"label"`
Score float64 `json:"score"`
}
//PredictResponse :
type PredictResponse struct {
Query string `json:"query"`
TopScoringIntent IntentScore `json:"topScoringIntent"`
TotalIntents []IntentScore `json:"intents"`
Entities interface{} `json:"entities"`
}
type IntentScore struct {
Intent string `json:"intent"`
Score float32 `json:"score"`
}
//NewPredictResponse :
func NewPredictResponse(raw []byte) *PredictResponse {
ret := &PredictResponse{}
err := json.Unmarshal(raw, &ret)
if err != nil {
log.Println("json unmarshal err:", err)
return ret
}
return ret
}
//GetBestScoreIntent :Get the best score intent prediction
func GetBestScoreIntent(preResult *PredictResponse) IntentScore {
return preResult.TopScoringIntent
}