-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
76 lines (61 loc) · 1.56 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
75
76
package main
import (
"os"
"strconv"
"strings"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/sashabaranov/go-openai"
)
var (
collectionDBPath = os.Getenv("COLLECTION_DB_PATH")
embeddingModel = os.Getenv("EMBEDDING_MODEL")
fileAssets = os.Getenv("FILE_ASSETS")
openAIKey = os.Getenv("OPENAI_API_KEY")
openAIBaseURL = os.Getenv("OPENAI_BASE_URL")
listeningAddress = os.Getenv("LISTENING_ADDRESS")
vectorEngine = os.Getenv("VECTOR_ENGINE")
maxChunkingSize = os.Getenv("MAX_CHUNKING_SIZE")
apiKeys = os.Getenv("API_KEYS")
)
func init() {
if collectionDBPath == "" {
collectionDBPath = "collections"
}
if fileAssets == "" {
fileAssets = "assets"
os.MkdirAll(fileAssets, 0755)
}
if listeningAddress == "" {
listeningAddress = ":8080"
}
if vectorEngine == "" {
vectorEngine = "chromem"
}
}
func startAPI(listenAddress string) {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
config := openai.DefaultConfig(openAIKey)
config.BaseURL = openAIBaseURL
openAIClient := openai.NewClientWithConfig(config)
registerStaticHandler(e)
keys := []string{}
if apiKeys != "" {
keys = strings.Split(apiKeys, ",")
}
chunkingSize := 400
if maxChunkingSize != "" {
var err error
chunkingSize, err = strconv.Atoi(maxChunkingSize)
if err != nil {
e.Logger.Fatal("Failed to convert MAX_CHUNKING_SIZE to integer")
}
}
registerAPIRoutes(e, openAIClient, chunkingSize, keys)
e.Logger.Fatal(e.Start(listenAddress))
}
func main() {
startAPI(listeningAddress)
}