|
8 | 8 | import com.alibaba.dashscope.utils.JsonUtils; |
9 | 9 | import com.google.gson.JsonObject; |
10 | 10 | import java.nio.ByteBuffer; |
| 11 | +import java.util.HashMap; |
11 | 12 | import java.util.List; |
| 13 | +import java.util.Map; |
12 | 14 | import lombok.EqualsAndHashCode; |
13 | 15 | import lombok.NonNull; |
14 | 16 | import lombok.experimental.SuperBuilder; |
|
18 | 20 | public class MultiModalEmbeddingParam extends HalfDuplexServiceParam { |
19 | 21 | @NonNull private List<MultiModalEmbeddingItemBase> contents; |
20 | 22 |
|
| 23 | + /** |
| 24 | + * The output vector dimensions. Supported values vary by model. For example, |
| 25 | + * multimodal-embedding-v1 outputs 1024-dimension vectors only and ignores this parameter, while |
| 26 | + * tongyi-embedding-vision-plus supports multiple dimensions (1152 by default). |
| 27 | + */ |
| 28 | + private Integer dimension; |
| 29 | + |
| 30 | + /** The output vector format. Currently only "dense" is supported. */ |
| 31 | + private String outputType; |
| 32 | + |
| 33 | + /** The video frame extraction ratio, in range [0, 1]. Default: 1.0. */ |
| 34 | + private Double fps; |
| 35 | + |
| 36 | + /** Custom task instruction to guide model understanding of query intent. */ |
| 37 | + private String instruct; |
| 38 | + |
| 39 | + /** |
| 40 | + * Only applicable to qwen3-vl-embedding. When true, all contents are fused into a single vector. |
| 41 | + */ |
| 42 | + private Boolean enableFusion; |
| 43 | + |
| 44 | + /** The resolution level of the input images/videos. */ |
| 45 | + private Integer resLevel; |
| 46 | + |
| 47 | + /** The maximum number of frames extracted from the input video. */ |
| 48 | + private Integer maxVideoFrames; |
| 49 | + |
21 | 50 | public List<MultiModalEmbeddingItemBase> getContent() { |
22 | 51 | return contents; |
23 | 52 | } |
24 | 53 |
|
| 54 | + @Override |
| 55 | + public Map<String, Object> getParameters() { |
| 56 | + Map<String, Object> params = new HashMap<>(); |
| 57 | + if (dimension != null) { |
| 58 | + params.put("dimension", dimension); |
| 59 | + } |
| 60 | + if (outputType != null) { |
| 61 | + params.put("output_type", outputType); |
| 62 | + } |
| 63 | + if (fps != null) { |
| 64 | + params.put("fps", fps); |
| 65 | + } |
| 66 | + if (instruct != null) { |
| 67 | + params.put("instruct", instruct); |
| 68 | + } |
| 69 | + if (enableFusion != null) { |
| 70 | + params.put("enable_fusion", enableFusion); |
| 71 | + } |
| 72 | + if (resLevel != null) { |
| 73 | + params.put("res_level", resLevel); |
| 74 | + } |
| 75 | + if (maxVideoFrames != null) { |
| 76 | + params.put("max_video_frames", maxVideoFrames); |
| 77 | + } |
| 78 | + if (parameters != null && !parameters.isEmpty()) { |
| 79 | + params.putAll(parameters); |
| 80 | + } |
| 81 | + return params; |
| 82 | + } |
| 83 | + |
25 | 84 | @Override |
26 | 85 | public JsonObject getHttpBody() { |
27 | 86 | JsonObject requestObject = new JsonObject(); |
28 | 87 | requestObject.addProperty(ApiKeywords.MODEL, getModel()); |
29 | 88 | requestObject.add(ApiKeywords.INPUT, getInput()); |
30 | | - if (parameters != null && !parameters.isEmpty()) { |
31 | | - requestObject.add(ApiKeywords.PARAMETERS, JsonUtils.parametersToJsonObject(getParameters())); |
| 89 | + Map<String, Object> params = getParameters(); |
| 90 | + if (params != null && !params.isEmpty()) { |
| 91 | + requestObject.add(ApiKeywords.PARAMETERS, JsonUtils.parametersToJsonObject(params)); |
32 | 92 | } |
33 | 93 | return requestObject; |
34 | 94 | } |
|
0 commit comments