feat: 实现基础的随机转发能力

This commit is contained in:
2024-01-18 17:32:23 +08:00
commit 0f1e287134
7 changed files with 316 additions and 0 deletions

43
config.go Normal file
View File

@@ -0,0 +1,43 @@
package main
import (
"fmt"
"github.com/spf13/viper"
)
type AiTarget struct {
TargetURL string `mapstructure:"Target"`
OpenAIKey string `mapstructure:"Key"`
}
type AppConfig struct {
InKeys []string `mapstructure:"InKeys"`
ApiPools map[string][]AiTarget `mapstructure:"ApiPools"`
}
var (
config *AppConfig
)
func InitConfig() {
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
v.SetConfigName("aiproxy")
v.SetConfigType("yaml")
v.AddConfigPath("/etc/")
v.AddConfigPath("$HOME/.config/")
v.AddConfigPath(".")
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal on read config file: %w", err))
}
err = v.Unmarshal(&config)
if err != nil {
panic(fmt.Errorf("fatal on parse config file: %w", err))
}
var models []string
for k, _ := range config.ApiPools {
models = append(models, k)
}
fmt.Printf("loaded models: %+v", models)
}