-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (52 loc) · 1.29 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
package main
import (
"encoding/json"
"github.com/KevinZonda/GoX/pkg/iox"
"github.com/gin-gonic/gin"
"github.com/promptc/api-server/api"
"github.com/promptc/api-server/cast"
scheduler "github.com/promptc/openai-scheduler"
)
func main() {
// Load config
cfgStr := e(iox.ReadAllText("config.json"))
var cfg cfgModel
if _e := json.Unmarshal([]byte(cfgStr), &cfg); _e != nil {
panic(_e)
}
// Init Prompt API Provider
openaiScheduler := scheduler.NewScheduler(cfg.Tokens)
apiProvider := api.NewProvider(
cast.SchedulerToOpenAIProvider(openaiScheduler),
[]string{
"echo.promptc",
"hello.promptc",
},
)
// Init Gin HTTP Server
engine := gin.New()
group := engine.Group("/v1")
// Append API Router
// /v1/echo -> echo.promptc
// /v1/hi -> hello.promptc (project: hi)
// /v1/hi/stream -> hello.promptc (project: hi, stream: true)
// /v1/echo/stream -> echo.promptc (stream: true)
// /v1/echo/info -> echo.promptc
// /v1/hi/info -> hello.promptc (project: hi)
apiProvider.AppendRouter(group)
// Start HTTP Server
err := engine.Run(cfg.ListenAddr)
if err != nil {
panic(err)
}
}
type cfgModel struct {
ListenAddr string `json:"listenAddr"`
Tokens []string `json:"tokens"`
}
func e[T any](i T, err error) T {
if err != nil {
panic(err)
}
return i
}