Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public String convertImageBlockToUrl(ImageBlock imageBlock) throws Exception {
public DashScopeContentPart convertImageBlockToContentPart(ImageBlock imageBlock)
throws Exception {
String imageUrl = convertImageBlockToUrl(imageBlock);
return DashScopeContentPart.image(imageUrl);
return DashScopeContentPart.builder()
.image(imageUrl)
.minPixels(imageBlock.getMinPixels())
.maxPixels(imageBlock.getMaxPixels())
.build();
}

/**
Expand Down Expand Up @@ -130,7 +134,14 @@ public String convertVideoBlockToUrl(VideoBlock videoBlock) throws Exception {
public DashScopeContentPart convertVideoBlockToContentPart(VideoBlock videoBlock)
throws Exception {
String videoUrl = convertVideoBlockToUrl(videoBlock);
return DashScopeContentPart.video(videoUrl);
return DashScopeContentPart.builder()
.video(videoUrl)
.fps(videoBlock.getFps())
.maxFrames(videoBlock.getMaxFrames())
.minPixels(videoBlock.getMinPixels())
.maxPixels(videoBlock.getMaxPixels())
.totalPixels(videoBlock.getTotalPixels())
.build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ public class DashScopeContentPart {
@JsonProperty("video")
private Object video;

/** Frames per second. The value range is [0.1, 10], and the default value is 2.0. */
@JsonProperty("fps")
private Float fps;

/** The maximum number of frames captured in the video. */
@JsonProperty("max_frames")
private Integer maxFrames;

/** Used to set the minimum pixel threshold for input image or video frames. */
@JsonProperty("min_pixels")
private Integer minPixels;

/** Used to set the maximum pixel threshold for input image or video frames. */
@JsonProperty("max_pixels")
private Integer maxPixels;

/** Used to limit the total pixels of all frames extracted from the video (single image pixels × total frames). */
@JsonProperty("total_pixels")
private Integer totalPixels;

public DashScopeContentPart() {}

public String getText() {
Expand Down Expand Up @@ -93,6 +113,46 @@ public void setVideo(Object video) {
this.video = video;
}

public Float getFps() {
return fps;
}

public void setFps(Float fps) {
this.fps = fps;
}

public Integer getMaxFrames() {
return maxFrames;
}

public void setMaxFrames(Integer maxFrames) {
this.maxFrames = maxFrames;
}

public Integer getMinPixels() {
return minPixels;
}

public void setMinPixels(Integer minPixels) {
this.minPixels = minPixels;
}

public Integer getMaxPixels() {
return maxPixels;
}

public void setMaxPixels(Integer maxPixels) {
this.maxPixels = maxPixels;
}

public Integer getTotalPixels() {
return totalPixels;
}

public void setTotalPixels(Integer totalPixels) {
this.totalPixels = totalPixels;
}

/**
* Get video as URL string.
*
Expand Down Expand Up @@ -205,6 +265,31 @@ public Builder video(Object video) {
return this;
}

public Builder fps(Float fps) {
part.setFps(fps);
return this;
}

public Builder maxFrames(Integer maxFrames) {
part.setMaxFrames(maxFrames);
return this;
}

public Builder minPixels(Integer minPixels) {
part.setMinPixels(minPixels);
return this;
}

public Builder maxPixels(Integer maxPixels) {
part.setMaxPixels(maxPixels);
return this;
}

public Builder totalPixels(Integer totalPixels) {
part.setTotalPixels(totalPixels);
return this;
}

public DashScopeContentPart build() {
return part;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.agentscope.core.message;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;

Expand All @@ -32,19 +33,41 @@
* need to process visual information from images, diagrams, screenshots,
* or other visual content.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class ImageBlock extends ContentBlock {

private final Source source;

private final Integer minPixels;

private final Integer maxPixels;

/**
* Creates a new image block with source.
*
* @param source The image source (URL or Base64)
* @throws NullPointerException if source is null
*/
public ImageBlock(@JsonProperty("source") Source source) {
this(source, null, null);
}

/**
* Creates a new image block for JSON deserialization.
*
* @param source The image source (URL or Base64)
* @param minPixels Used to set the minimum pixel threshold for input image.
* @param maxPixels Used to set the maximum pixel threshold for input image.
* @throws NullPointerException if source is null
*/
@JsonCreator
public ImageBlock(@JsonProperty("source") Source source) {
private ImageBlock(
@JsonProperty("source") Source source,
@JsonProperty("min_pixels") Integer minPixels,
@JsonProperty("max_pixels") Integer maxPixels) {
this.source = Objects.requireNonNull(source, "source cannot be null");
this.minPixels = minPixels;
this.maxPixels = maxPixels;
}

/**
Expand All @@ -56,6 +79,24 @@ public Source getSource() {
return source;
}

/**
* Gets the minimum pixel threshold for input image.
*
* @return The minimum pixel threshold
*/
public Integer getMinPixels() {
return minPixels;
}

/**
* Gets the maximum pixel threshold for input image.
*
* @return The maximum pixel threshold
*/
public Integer getMaxPixels() {
return maxPixels;
}

/**
* Creates a new builder for constructing ImageBlock instances.
*
Expand All @@ -72,6 +113,10 @@ public static class Builder {

private Source source;

private Integer minPixels;

private Integer maxPixels;

/**
* Sets the source for the image.
*
Expand All @@ -83,14 +128,36 @@ public Builder source(Source source) {
return this;
}

/**
* Sets the minimum pixel threshold for input image frames.
*
* @param minPixels The minimum pixel threshold
* @return This builder for chaining
*/
public Builder minPixels(Integer minPixels) {
this.minPixels = minPixels;
return this;
}

/**
* Sets the maximum pixel threshold for input image frames.
*
* @param maxPixels The maximum pixel threshold
* @return This builder for chaining
*/
public Builder maxPixels(Integer maxPixels) {
this.maxPixels = maxPixels;
return this;
}

/**
* Builds a new ImageBlock with the configured source.
*
* @return A new ImageBlock instance
* @throws NullPointerException if source is null
*/
public ImageBlock build() {
return new ImageBlock(source);
return new ImageBlock(source, minPixels, maxPixels);
}
}
}
Loading
Loading