package agent import ( "context" "fmt" "github.com/gogf/gf/v2/frame/g" ) // ImageGenClient 图像生成客户端(真实调用,无 mock) type ImageGenClient interface { // Generate 生成单张图片,返回图片 URL(可传 BaseImageURL 做图生图,为空则文生图) Generate(ctx context.Context, req *GenerateReq) (string, error) } // GenerateReq 生成请求 type GenerateReq struct { BaseImageURL string // 用户全身照(本地 /workspace 路径或 http(s) URL,空为文生图) Prompt string // 方案描述 Angle string // 正面/侧面/背面 Seed int64 } // NewClient 创建真实图像生成客户端;未配置供应商或 Key 时返回错误(不再降级 mock) func NewClient(supplier string) (ImageGenClient, error) { if supplier == "wanx" { key := g.Cfg().MustGet(context.Background(), "imagegen.wanx_api_key", "").String() if key != "" { return &wanxClient{ apiKey: key, model: g.Cfg().MustGet(context.Background(), "imagegen.wanx_model", "wan2.7-image-pro").String(), base: g.Cfg().MustGet(context.Background(), "imagegen.wanx_base", "https://dashscope.aliyuncs.com/api/v1/services/aigc/image-generation/generation").String(), taskBase: g.Cfg().MustGet(context.Background(), "imagegen.wanx_task_base", "https://dashscope.aliyuncs.com/api/v1/tasks").String(), }, nil } return nil, fmt.Errorf("imagegen 未配置:请在 config.yml 设置 imagegen.wanx_api_key") } return nil, fmt.Errorf("imagegen 供应商不支持:%s(当前仅支持 wanx)", supplier) } // buildPrompt 组装图片生成提示词 func buildPrompt(planDesc, hairstyle, hairColor, angle string) string { return fmt.Sprintf("时尚穿搭效果图,%s;发型:%s(发色 %s);角度:%s;人物写实、高清、全身、纯色背景", planDesc, hairstyle, hairColor, angle) }