-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
74 lines (62 loc) · 1.62 KB
/
main.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
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/Kardbord/hfapigo/v3"
)
const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
func init() {
key := os.Getenv(HuggingFaceTokenEnv)
if key != "" {
hfapigo.SetAPIKey(key)
}
}
func main() {
inputs := []string{
"Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
"Hi, I am having a difficult time using your product. Do you have a manual or perhaps a list of frequently asked questions to help get me going?",
}
candidateLabels := []string{"refund", "legal", "faq"}
model := hfapigo.RecommendedZeroShotModel
fmt.Printf("Inputs: [\"%s\"]\n", strings.Join(inputs, `", "`))
fmt.Printf("CandidateLabels: %v\n", candidateLabels)
fmt.Printf("Model: %s\n", hfapigo.RecommendedZeroShotModel)
fmt.Printf("\nSending request")
type ChanRv struct {
resps []*hfapigo.ZeroShotResponse
err error
}
ch := make(chan ChanRv)
go func() {
zresps, err := hfapigo.SendZeroShotRequest(model, &hfapigo.ZeroShotRequest{
Inputs: inputs,
Parameters: hfapigo.ZeroShotParameters{
CandidateLabels: candidateLabels,
},
Options: *hfapigo.NewOptions().SetWaitForModel(true),
})
ch <- ChanRv{zresps, err}
}()
for {
select {
case chrv := <-ch:
if chrv.err != nil {
fmt.Println(chrv.err)
return
}
fmt.Println()
for _, resp := range chrv.resps {
fmt.Println("\nSequence:", resp.Sequence)
for i, label := range resp.Labels {
fmt.Printf("%s: %f\n", label, resp.Scores[i])
}
}
return
default:
fmt.Print(".")
time.Sleep(time.Millisecond * 100)
}
}
}