-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
66 lines (54 loc) · 1.66 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
package main
import (
"os"
"github.com/deepset-ai/prompthub/api"
"github.com/deepset-ai/prompthub/index"
"github.com/deepset-ai/prompthub/output"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
func main() {
// Define and parse command args
verbosity := pflag.IntP("verbose", "v", 1, "set verbosity level: 0 silent, 1 normal, 2 debug")
configPath := pflag.StringP("config", "c", "", "path to config file")
help := pflag.BoolP("help", "h", false, "print args help")
pflag.Parse()
// Print the help message and exit if --help is passed
if *help {
pflag.PrintDefaults()
os.Exit(0)
}
// Configure cmdline output facilities
output.Init(*verbosity)
// Bootstrap config, this has to be called first
initConfig(configPath)
// Initialize the index by reading all the prompts from file
if err := index.Init(viper.GetString("prompts_path")); err != nil {
os.Exit(1)
}
// Start the HTTP server, block until shutdown
api.Serve()
os.Exit(0)
}
func initConfig(configPath *string) {
// Defaults
viper.SetDefault("port", "80")
viper.SetDefault("prompts_path", "./prompts")
viper.SetDefault("allowed_origins", []string{"https://prompthub.deepset.ai"})
// Automatically bind all the config options to env vars
viper.SetEnvPrefix("prompthub")
viper.AutomaticEnv()
// Setup the config lookup
viper.SetConfigName("prompthub.yaml")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
if *configPath != "" {
viper.AddConfigPath(*configPath)
}
err := viper.ReadInConfig()
if err != nil {
output.INFO.Println("Configuration file not found, running with default parameters")
} else {
output.DEBUG.Println("Config file found at", viper.ConfigFileUsed())
}
}