forked from go-aie/gptbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 1.07 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/RussellLuo/kun/pkg/httpcodec"
"github.com/coseyo/gptbot"
"github.com/coseyo/gptbot/milvus"
)
func main() {
apiKey := os.Getenv("OPENAI_API_KEY")
encoder := gptbot.NewOpenAIEncoder(apiKey, "")
store, err := milvus.NewMilvus(&milvus.Config{
CollectionName: "gptbot",
})
if err != nil {
log.Fatalf("err: %v", err)
}
feeder := gptbot.NewFeeder(&gptbot.FeederConfig{
Encoder: encoder,
Updater: store,
})
bot := gptbot.NewBot(&gptbot.BotConfig{
APIKey: apiKey,
Encoder: encoder,
Querier: store,
})
svc := NewGPTBot(feeder, store, bot)
r := NewHTTPRouter(svc, httpcodec.NewDefaultCodecs(nil, httpcodec.Op(
"UploadFile", httpcodec.NewMultipartForm(0),
)))
errs := make(chan error, 2)
go func() {
log.Printf("transport=HTTP addr=%s\n", ":8080")
errs <- http.ListenAndServe(":8080", r)
}()
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
errs <- fmt.Errorf("%s", <-c)
}()
log.Printf("terminated, err:%v", <-errs)
}