Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion samples/ImageGenerationUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.alibaba.dashscope.task.AsyncTaskListParam;
import io.reactivex.Flowable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ImageGenerationUsage {

Expand Down Expand Up @@ -123,12 +125,42 @@ public static void imageUsageStream() throws NoApiKeyException, UploadFileExcept
res.blockingForEach(System.out::println);
}

static ImageGenerationMessage wan27ImageMessage = ImageGenerationMessage.builder()
.role(Role.USER.getValue())
.content(Arrays.asList(
Collections.singletonMap("image", "https://img.alicdn.com/imgextra/i3/O1CN0157XGE51l6iL9441yX_!!6000000004770-49-tps-1104-1472.webp"),
Collections.singletonMap("image", "https://img.alicdn.com/imgextra/i3/O1CN01SfG4J41UYn9WNt4X1_!!6000000002530-49-tps-1696-960.webp"),
Collections.singletonMap("text", "把图1的闹钟放在图2的框选的位置,保持场景和光线融合自然")
)).build();

static List<List<List<Integer>>> bboxList = Arrays.asList(
new ArrayList<>(),
Collections.singletonList(
Arrays.asList(989, 515, 1138, 681)
)
);

public static void wan27ImageUsage() throws NoApiKeyException, UploadFileException {
ImageGenerationParam param = ImageGenerationParam.builder()
.apiKey(DASHSCOPE_API_KEY)
.model("wan2.7-image-pro")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The model name "wan2.7-image-pro" is hardcoded as a string literal. It is recommended to define this as a constant in the ImageGeneration.Models class to maintain consistency with other models and avoid magic strings throughout the codebase.

.n(1)
.messages(Collections.singletonList(wan27ImageMessage))
.bboxList(bboxList)
.build();

ImageGeneration ig = new ImageGeneration();
ImageGenerationResult res =ig.call(param);
System.out.println(res);
}

public static void main(String[] args) {
try {
t2iUsage();
// t2iUsage();
// imageUsage();
// t2iUsageAsync();
// imageUsageStream();
wan27ImageUsage();
}catch (NoApiKeyException | UploadFileException e){
System.out.println(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class ImageGenerationParam extends HalfDuplexServiceParam {

private Boolean enableSequential;

/**
* The bounding boxes for the images. The structure is [image_index][box_index][x1, y1, x2, y2].
*/
@Builder.Default private List<List<List<Integer>>> bboxList = null;

@Override
public JsonObject getHttpBody() {
JsonObject requestObject = new JsonObject();
Expand Down Expand Up @@ -158,6 +163,10 @@ public Map<String, Object> getParameters() {
params.put("enable_sequential", enableSequential);
}

if (bboxList != null) {
params.put("bbox_list", bboxList);
}

params.putAll(parameters);
return params;
}
Expand Down
Loading