fix: 为图片生成 API 添加超时与 5xx 重试机制
- ImageGenConfig 新增 timeout/max_retries/retry_delay 配置项(默认 120s/2次/5s) - 替换 http.DefaultClient 为带超时的 imageHTTPClient - callImageAPI 对 5xx 错误自动重试,避免 504 等瞬时故障直接失败
This commit is contained in:
@@ -46,12 +46,15 @@ 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 七牛云对象存储配置。
|
||||
@@ -117,6 +120,9 @@ 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)
|
||||
@@ -148,6 +154,9 @@ 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")
|
||||
|
||||
Reference in New Issue
Block a user