fix(inference): 修正文生图 API 调用参数,支持动态分辨率
- 去掉 response_format 参数(API 默认返回 URL,自动下载) - Resolution 参数覆盖 API 调用尺寸(不再仅 mock 路径生效) - parseImageResponse 改为动态 width/height 入参 - 新增 tools/gentest.go 生成测试脚本 - .gitignore 忽略 test_output/
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gen2d/internal/config"
|
||||
"gen2d/internal/service"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
|
||||
// 清空 API key 强制走 mock
|
||||
cfg.ImageGen.APIKey = ""
|
||||
service.InitImageGenConfig(cfg.ImageGen)
|
||||
service.InitLLMConfig(cfg.LLM)
|
||||
|
||||
in := service.PipelineInput{
|
||||
AssetType: "sprite",
|
||||
Prompt: "a cute cat warrior with golden armor",
|
||||
Tags: []string{"pixel art", "fantasy", "16-bit"},
|
||||
Params: service.AssetParams{
|
||||
Resolution: 816,
|
||||
Frames: service.FrameParams{Directions: 4, FramesPerDirection: 1},
|
||||
Format: "individual",
|
||||
},
|
||||
}
|
||||
|
||||
output, err := service.RunPipeline(context.Background(), in)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.MkdirAll("test_output", 0755)
|
||||
for i, a := range output.Assets {
|
||||
fname := fmt.Sprintf("test_output/gen_%d.%s", i, a.Format)
|
||||
if err := os.WriteFile(fname, a.Data, 0644); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "write %s: %v\n", fname, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("saved %s (%d bytes)\n", fname, len(a.Data))
|
||||
}
|
||||
fmt.Printf("metadata: %+v\n", output.Metadata)
|
||||
}
|
||||
Reference in New Issue
Block a user