feat(inference): 集成 GPT Image 2 异步文生图 API
- 新增 GptImage2Config 配置(yuntts 等 GPT Image 2 兼容服务) - 新增 gptimage.go 异步客户端:提交任务 → 轮询状态 → 下载图片 - GenerateImages 优先级调整为:GPT Image 2 > OpenAI 兼容 ImageGen > Mock - 支持环境变量 GEN2D_GPT_IMAGE2_* 系列配置
This commit is contained in:
Regular → Executable
+15
-2
@@ -48,13 +48,25 @@ type imageGenResponse struct {
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// GenerateImages 调用 AI 推理 API 生成图片,未配置 API key 时回退到 mock。
|
||||
// GenerateImages 调用 AI 推理 API 生成图片。
|
||||
// 优先级:GPT Image 2 > OpenAI 兼容 ImageGen > Mock 回退。
|
||||
func GenerateImages(ctx context.Context, prompt string, params AssetParams) ([]GeneratedImage, error) {
|
||||
count := 1
|
||||
if params.Frames.Directions > 0 && params.Frames.FramesPerDirection > 0 {
|
||||
count = params.Frames.Directions * params.Frames.FramesPerDirection
|
||||
}
|
||||
|
||||
// 优先使用 GPT Image 2 异步 API
|
||||
if gptImage2Cfg.APIKey != "" {
|
||||
log.Println("[inference] using GPT Image 2 async API")
|
||||
images, err := GenerateImagesGpt2(ctx, prompt, count)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gpt_image2: %w", err)
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
// 降级:OpenAI 兼容 Images API
|
||||
if imgCfg.APIKey != "" {
|
||||
width, height := imgCfg.Width, imgCfg.Height
|
||||
if params.Resolution > 0 {
|
||||
@@ -64,11 +76,12 @@ func GenerateImages(ctx context.Context, prompt string, params AssetParams) ([]G
|
||||
return callImageGenAPI(ctx, prompt, count, width, height)
|
||||
}
|
||||
|
||||
// 最终降级:mock 占位图
|
||||
size := params.Resolution
|
||||
if size <= 0 {
|
||||
size = 64
|
||||
}
|
||||
log.Println("[inference] ImageGen API key not configured, using mock")
|
||||
log.Println("[inference] no image API key configured, using mock")
|
||||
return generateMockImages(size, count)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user