refactor(inference): 统合 image_gen 为 GPT Image 2 异步 API,删除冗余配置
- 删除 gptimage.go,异步逻辑直接内聚到 inference.go - ImageGenConfig 改为 GPT Image 2 参数:aspect_ratio / x_channel / poll_max_wait / poll_interval - GenerateImages 流程:submit → poll → download,支持并行多图(spritesheet) - 移除旧的 OpenAI 兼容同步 API 代码(callImageGenAPI / parseImageResponse 等) - 统一 env:GEN2D_IMAGE_* 系列,移除 GEN2D_GPT_IMAGE2_* 冗余
This commit is contained in:
@@ -9,12 +9,11 @@ import (
|
||||
|
||||
// Config 应用全局配置。
|
||||
type Config struct {
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
Database DatabaseConfig `mapstructure:"database"`
|
||||
JWT JWTConfig `mapstructure:"jwt"`
|
||||
LLM LLMConfig `mapstructure:"llm"`
|
||||
ImageGen ImageGenConfig `mapstructure:"image_gen"`
|
||||
GptImage2 GptImage2Config `mapstructure:"gpt_image2"`
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
Database DatabaseConfig `mapstructure:"database"`
|
||||
JWT JWTConfig `mapstructure:"jwt"`
|
||||
LLM LLMConfig `mapstructure:"llm"`
|
||||
ImageGen ImageGenConfig `mapstructure:"image_gen"`
|
||||
}
|
||||
|
||||
// ServerConfig HTTP 服务配置。
|
||||
@@ -44,26 +43,16 @@ type LLMConfig struct {
|
||||
MaxTokens int `mapstructure:"max_tokens"`
|
||||
}
|
||||
|
||||
// ImageGenConfig 文生图模型配置(OpenAI 兼容同步 API)。
|
||||
// ImageGenConfig GPT Image 2 异步生图模型配置。
|
||||
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"`
|
||||
NumImages int `mapstructure:"num_images"`
|
||||
Steps int `mapstructure:"steps"`
|
||||
CFGScale float64 `mapstructure:"cfg_scale"`
|
||||
}
|
||||
|
||||
// GptImage2Config GPT Image 2 异步生图模型配置(yuntts 等兼容服务)。
|
||||
type GptImage2Config struct {
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
AspectRatio string `mapstructure:"aspect_ratio"`
|
||||
XChannel string `mapstructure:"x_channel"`
|
||||
PollMaxWait int `mapstructure:"poll_max_wait"` // 轮询最大等待秒数, 默认 120
|
||||
PollInterval int `mapstructure:"poll_interval"` // 轮询间隔秒数, 默认 3
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
Model string `mapstructure:"model"`
|
||||
Quality string `mapstructure:"quality"`
|
||||
AspectRatio string `mapstructure:"aspect_ratio"`
|
||||
XChannel string `mapstructure:"x_channel"`
|
||||
PollMaxWait int `mapstructure:"poll_max_wait"`
|
||||
PollInterval int `mapstructure:"poll_interval"`
|
||||
}
|
||||
|
||||
// Load 从 YAML 配置文件和环境变量加载配置。
|
||||
@@ -114,21 +103,14 @@ func setDefaults(v *viper.Viper) {
|
||||
v.SetDefault("llm.temperature", 0.7)
|
||||
v.SetDefault("llm.max_tokens", 2048)
|
||||
|
||||
v.SetDefault("image_gen.base_url", "https://api.stability.ai/v1")
|
||||
v.SetDefault("image_gen.base_url", "https://www.yuntts.com/api/v1")
|
||||
v.SetDefault("image_gen.api_key", "")
|
||||
v.SetDefault("image_gen.model", "stable-diffusion-xl")
|
||||
v.SetDefault("image_gen.width", 1024)
|
||||
v.SetDefault("image_gen.height", 1024)
|
||||
v.SetDefault("image_gen.num_images", 1)
|
||||
v.SetDefault("image_gen.steps", 30)
|
||||
v.SetDefault("image_gen.cfg_scale", 7.0)
|
||||
|
||||
v.SetDefault("gpt_image2.base_url", "https://www.yuntts.com/api/v1")
|
||||
v.SetDefault("gpt_image2.api_key", "")
|
||||
v.SetDefault("gpt_image2.aspect_ratio", "1:1")
|
||||
v.SetDefault("gpt_image2.x_channel", "default")
|
||||
v.SetDefault("gpt_image2.poll_max_wait", 120)
|
||||
v.SetDefault("gpt_image2.poll_interval", 3)
|
||||
v.SetDefault("image_gen.model", "gpt-image-2")
|
||||
v.SetDefault("image_gen.quality", "low")
|
||||
v.SetDefault("image_gen.aspect_ratio", "1:1")
|
||||
v.SetDefault("image_gen.x_channel", "default")
|
||||
v.SetDefault("image_gen.poll_max_wait", 120)
|
||||
v.SetDefault("image_gen.poll_interval", 3)
|
||||
}
|
||||
|
||||
func bindEnvVars(v *viper.Viper) {
|
||||
@@ -148,16 +130,9 @@ func bindEnvVars(v *viper.Viper) {
|
||||
v.BindEnv("image_gen.base_url", "GEN2D_IMAGE_BASE_URL")
|
||||
v.BindEnv("image_gen.api_key", "GEN2D_IMAGE_API_KEY")
|
||||
v.BindEnv("image_gen.model", "GEN2D_IMAGE_MODEL")
|
||||
v.BindEnv("image_gen.width", "GEN2D_IMAGE_WIDTH")
|
||||
v.BindEnv("image_gen.height", "GEN2D_IMAGE_HEIGHT")
|
||||
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("gpt_image2.base_url", "GEN2D_GPT_IMAGE2_BASE_URL")
|
||||
v.BindEnv("gpt_image2.api_key", "GEN2D_GPT_IMAGE2_API_KEY")
|
||||
v.BindEnv("gpt_image2.aspect_ratio", "GEN2D_GPT_IMAGE2_ASPECT_RATIO")
|
||||
v.BindEnv("gpt_image2.x_channel", "GEN2D_GPT_IMAGE2_X_CHANNEL")
|
||||
v.BindEnv("gpt_image2.poll_max_wait", "GEN2D_GPT_IMAGE2_POLL_MAX_WAIT")
|
||||
v.BindEnv("gpt_image2.poll_interval", "GEN2D_GPT_IMAGE2_POLL_INTERVAL")
|
||||
v.BindEnv("image_gen.quality", "GEN2D_IMAGE_QUALITY")
|
||||
v.BindEnv("image_gen.aspect_ratio", "GEN2D_IMAGE_ASPECT_RATIO")
|
||||
v.BindEnv("image_gen.x_channel", "GEN2D_IMAGE_X_CHANNEL")
|
||||
v.BindEnv("image_gen.poll_max_wait", "GEN2D_IMAGE_POLL_MAX_WAIT")
|
||||
v.BindEnv("image_gen.poll_interval", "GEN2D_IMAGE_POLL_INTERVAL")
|
||||
}
|
||||
|
||||
Regular → Executable
+7
-7
@@ -21,11 +21,11 @@ llm:
|
||||
max_tokens: 2048
|
||||
|
||||
image_gen:
|
||||
base_url: "https://api.stability.ai/v1"
|
||||
base_url: "https://www.yuntts.com/api/v1"
|
||||
api_key: ""
|
||||
model: "stable-diffusion-xl"
|
||||
width: 1024
|
||||
height: 1024
|
||||
num_images: 1
|
||||
steps: 30
|
||||
cfg_scale: 7.0
|
||||
model: "gpt-image-2"
|
||||
quality: "low"
|
||||
aspect_ratio: "1:1"
|
||||
x_channel: "default"
|
||||
poll_max_wait: 120
|
||||
poll_interval: 3
|
||||
|
||||
Reference in New Issue
Block a user