-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_test.go
More file actions
72 lines (55 loc) · 1.49 KB
/
Copy pathexample_test.go
File metadata and controls
72 lines (55 loc) · 1.49 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
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
package luis_test
import (
"fmt"
"os"
"github.com/kkdai/luis"
"github.com/prometheus/common/log"
)
func Example() {
var API_KEY string
var APPID string
APPID = os.Getenv("APP_ID")
API_KEY = os.Getenv("SUB_KEY")
if API_KEY == "" {
fmt.Println("Please export your key to environment first, `export SUB_KEY=12234 && export APP_ID=5678`")
return
}
e := luis.NewLuis(API_KEY, APPID)
res, err := e.IntelList()
if err != nil {
log.Error("Error happen on :", err.Err)
}
fmt.Println("Got response:", string(res))
result := luis.NewIntentListResponse(res)
fmt.Println("Luis Intent Ret", result)
//Add utterances
ex := luis.ExamplePayload{ExampleText: "test", SelectedIntentName: "test2"}
res, err = e.AddLabel(ex)
//Train it
res, err = e.Train()
if err != nil {
log.Error("Error happen on :", err.Err)
}
//Predict it, once you have train your models.
res, err = e.Predict("test string")
if err != nil {
log.Error("Error happen on :", err.Err)
}
fmt.Println("Got response:", string(res))
fmt.Println("Get the best predict result:", luis.GetBestScoreIntent(luis.NewPredictResponse(res)))
}
func ExampleIntelList() {
var API_KEY string
var APPID string
APPID = os.Getenv("APP_ID")
API_KEY = os.Getenv("SUB_KEY")
if API_KEY == "" {
fmt.Println("Please export your key to environment first, `export SUB_KEY=12234 && export APP_ID=5678`")
return
}
e := luis.NewLuis(API_KEY, APPID)
_, err := e.IntelList()
if err != nil {
log.Error("Error happen on :", err.Err)
}
}