Merge branch 'develop' of gitee.com:hezhaohui123/gen2d into feat/async-generate-pipeline
Signed-off-by: 何朝晖 <hezhaohui0807@163.com>
This commit is contained in:
@@ -12,8 +12,16 @@ type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
Database DatabaseConfig `mapstructure:"database"`
|
||||
JWT JWTConfig `mapstructure:"jwt"`
|
||||
Log LogConfig `mapstructure:"log"`
|
||||
LLM LLMConfig `mapstructure:"llm"`
|
||||
ImageGen ImageGenConfig `mapstructure:"image_gen"`
|
||||
Qiniu QiniuConfig `mapstructure:"qiniu"`
|
||||
}
|
||||
|
||||
// LogConfig 日志配置。
|
||||
type LogConfig struct {
|
||||
Level string `mapstructure:"level"` // debug / info / warn / error
|
||||
Format string `mapstructure:"format"` // text / json
|
||||
}
|
||||
|
||||
// ServerConfig HTTP 服务配置。
|
||||
@@ -45,12 +53,24 @@ type LLMConfig struct {
|
||||
|
||||
// ImageGenConfig OpenAI 兼容文生图模型配置。
|
||||
type ImageGenConfig struct {
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
Model string `mapstructure:"model"`
|
||||
Width int `mapstructure:"width"`
|
||||
Height int `mapstructure:"height"`
|
||||
Quality string `mapstructure:"quality"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
Model string `mapstructure:"model"`
|
||||
Width int `mapstructure:"width"`
|
||||
Height int `mapstructure:"height"`
|
||||
Quality string `mapstructure:"quality"`
|
||||
Timeout int `mapstructure:"timeout"` // HTTP 请求超时秒数,默认 120
|
||||
MaxRetries int `mapstructure:"max_retries"` // 5xx 错误重试次数,默认 2
|
||||
RetryDelay int `mapstructure:"retry_delay"` // 重试间隔秒数,默认 5
|
||||
}
|
||||
|
||||
// QiniuConfig 七牛云对象存储配置。
|
||||
type QiniuConfig struct {
|
||||
AccessKey string `mapstructure:"access_key"`
|
||||
SecretKey string `mapstructure:"secret_key"`
|
||||
Bucket string `mapstructure:"bucket"`
|
||||
CDNHost string `mapstructure:"cdn_host"`
|
||||
UseHTTPS bool `mapstructure:"use_https"`
|
||||
}
|
||||
|
||||
// Load 从 YAML 配置文件和环境变量加载配置。
|
||||
@@ -90,6 +110,9 @@ func setDefaults(v *viper.Viper) {
|
||||
v.SetDefault("server.mode", "debug")
|
||||
v.SetDefault("server.max_file_size", int64(10<<20))
|
||||
|
||||
v.SetDefault("log.level", "info")
|
||||
v.SetDefault("log.format", "text")
|
||||
|
||||
v.SetDefault("database.dsn", "data/gen2d.db")
|
||||
|
||||
v.SetDefault("jwt.secret", "gen2d-dev-secret")
|
||||
@@ -107,6 +130,18 @@ func setDefaults(v *viper.Viper) {
|
||||
v.SetDefault("image_gen.width", 1024)
|
||||
v.SetDefault("image_gen.height", 1024)
|
||||
v.SetDefault("image_gen.quality", "low")
|
||||
v.SetDefault("image_gen.timeout", 120)
|
||||
v.SetDefault("image_gen.max_retries", 2)
|
||||
v.SetDefault("image_gen.retry_delay", 5)
|
||||
v.SetDefault("image_gen.num_images", 1)
|
||||
v.SetDefault("image_gen.steps", 30)
|
||||
v.SetDefault("image_gen.cfg_scale", 7.0)
|
||||
|
||||
v.SetDefault("qiniu.access_key", "")
|
||||
v.SetDefault("qiniu.secret_key", "")
|
||||
v.SetDefault("qiniu.bucket", "")
|
||||
v.SetDefault("qiniu.cdn_host", "")
|
||||
v.SetDefault("qiniu.use_https", true)
|
||||
}
|
||||
|
||||
func bindEnvVars(v *viper.Viper) {
|
||||
@@ -114,6 +149,9 @@ func bindEnvVars(v *viper.Viper) {
|
||||
v.BindEnv("server.mode", "GEN2D_MODE")
|
||||
v.BindEnv("server.max_file_size", "GEN2D_MAX_FILE_SIZE")
|
||||
v.BindEnv("database.dsn", "GEN2D_DSN")
|
||||
|
||||
v.BindEnv("log.level", "GEN2D_LOG_LEVEL")
|
||||
v.BindEnv("log.format", "GEN2D_LOG_FORMAT")
|
||||
v.BindEnv("jwt.secret", "GEN2D_JWT_SECRET")
|
||||
v.BindEnv("jwt.expire", "GEN2D_JWT_EXPIRE")
|
||||
|
||||
@@ -129,4 +167,16 @@ func bindEnvVars(v *viper.Viper) {
|
||||
v.BindEnv("image_gen.width", "GEN2D_IMAGE_WIDTH")
|
||||
v.BindEnv("image_gen.height", "GEN2D_IMAGE_HEIGHT")
|
||||
v.BindEnv("image_gen.quality", "GEN2D_IMAGE_QUALITY")
|
||||
v.BindEnv("image_gen.timeout", "GEN2D_IMAGE_TIMEOUT")
|
||||
v.BindEnv("image_gen.max_retries", "GEN2D_IMAGE_MAX_RETRIES")
|
||||
v.BindEnv("image_gen.retry_delay", "GEN2D_IMAGE_RETRY_DELAY")
|
||||
v.BindEnv("image_gen.num_images", "GEN2D_IMAGE_NUM_IMAGES")
|
||||
v.BindEnv("image_gen.steps", "GEN2D_IMAGE_STEPS")
|
||||
v.BindEnv("image_gen.cfg_scale", "GEN2D_IMAGE_CFG_SCALE")
|
||||
|
||||
v.BindEnv("qiniu.access_key", "GEN2D_QINIU_ACCESS_KEY")
|
||||
v.BindEnv("qiniu.secret_key", "GEN2D_QINIU_SECRET_KEY")
|
||||
v.BindEnv("qiniu.bucket", "GEN2D_QINIU_BUCKET")
|
||||
v.BindEnv("qiniu.cdn_host", "GEN2D_QINIU_CDN_HOST")
|
||||
v.BindEnv("qiniu.use_https", "GEN2D_QINIU_USE_HTTPS")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ server:
|
||||
mode: debug
|
||||
max_file_size: 10485760 # 10MB
|
||||
|
||||
log:
|
||||
level: info # debug / info / warn / error
|
||||
format: text # text / json
|
||||
|
||||
database:
|
||||
dsn: "data/gen2d.db"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user