1313import com .alibaba .dashscope .utils .PreprocessInputImage ;
1414import com .google .gson .JsonObject ;
1515import java .nio .ByteBuffer ;
16+ import java .util .ArrayList ;
1617import java .util .HashMap ;
18+ import java .util .List ;
1719import java .util .Map ;
1820import lombok .Builder ;
1921import lombok .Data ;
@@ -35,6 +37,7 @@ public class ImageSynthesisParam extends HalfDuplexServiceParam {
3537 private String negativePrompt ;
3638 private String refImage ;
3739 private String sketchImageUrl ;
40+ private List <String > images ;
3841
3942 /** The specific functions to be achieved , see class ImageEditFunction */
4043 @ Builder .Default private String function = null ;
@@ -78,6 +81,9 @@ public JsonObject getInput() {
7881 if (maskImageUrl != null && !maskImageUrl .isEmpty ()) {
7982 jsonObject .addProperty (MASK_IMAGE_URL , maskImageUrl );
8083 }
84+ if (images != null && !images .isEmpty ()) {
85+ jsonObject .add (IMAGES , JsonUtils .toJsonArray (images ));
86+ }
8187 if (extraInputs != null && !extraInputs .isEmpty ()) {
8288 JsonObject extraInputsJsonObject = JsonUtils .parametersToJsonObject (extraInputs );
8389 jsonObject = JsonUtils .merge (jsonObject , extraInputsJsonObject );
@@ -147,6 +153,10 @@ public void checkAndUpload() throws NoApiKeyException, UploadFileException {
147153 inputChecks .put (SKETCH_IMAGE_URL , this .sketchImageUrl );
148154 inputChecks .put (BASE_IMAGE_URL , this .baseImageUrl );
149155 inputChecks .put (MASK_IMAGE_URL , this .maskImageUrl );
156+ int imagesSize = this .images .size ();
157+ for (int i = 0 ; i < imagesSize ; i ++) {
158+ inputChecks .put (IMAGES + "[" + i + "]" , this .images .get (i ));
159+ }
150160
151161 boolean isUpload = PreprocessInputImage .checkAndUploadImage (getModel (), inputChecks , getApiKey ());
152162
@@ -157,6 +167,13 @@ public void checkAndUpload() throws NoApiKeyException, UploadFileException {
157167 this .sketchImageUrl = inputChecks .get (SKETCH_IMAGE_URL );
158168 this .baseImageUrl = inputChecks .get (BASE_IMAGE_URL );
159169 this .maskImageUrl = inputChecks .get (MASK_IMAGE_URL );
170+ List <String > newImages = new ArrayList <>();
171+ for (int i = 0 ; i < imagesSize ; i ++) {
172+ newImages .add (inputChecks .get (IMAGES + "[" + i + "]" ));
173+ }
174+ if (!newImages .isEmpty ()) {
175+ this .images = newImages ;
176+ }
160177 }
161178 }
162179}
0 commit comments