Skip to content

Commit 6e01d0d

Browse files
committed
fix(qwen3-vl): invalid incremental output
1 parent 34fce3b commit 6e01d0d

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

src/main/java/com/alibaba/dashscope/aigc/generation/GenerationParam.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.alibaba.dashscope.exception.InputRequiredException;
1616
import com.alibaba.dashscope.tools.ToolBase;
1717
import com.alibaba.dashscope.utils.JsonUtils;
18+
import com.alibaba.dashscope.utils.ParamUtils;
1819
import com.google.gson.JsonArray;
1920
import com.google.gson.JsonObject;
2021
import com.google.gson.annotations.SerializedName;
@@ -190,32 +191,8 @@ public Map<String, Object> getParameters() {
190191
if (temperature != null) {
191192
params.put("temperature", temperature);
192193
}
193-
// Check if model is qwen{n} where n >= 3
194-
String modelName = getModel();
195-
boolean isQwenVersionThreeOrHigher = false;
196-
if (modelName.toLowerCase().startsWith("qwen")) {
197-
String remaining = modelName.toLowerCase().substring(4);
198-
try {
199-
// Extract the number after "qwen"
200-
StringBuilder numberStr = new StringBuilder();
201-
for (char c : remaining.toCharArray()) {
202-
if (Character.isDigit(c)) {
203-
numberStr.append(c);
204-
} else {
205-
break;
206-
}
207-
}
208-
if (numberStr.length() > 0) {
209-
int version = Integer.parseInt(numberStr.toString());
210-
isQwenVersionThreeOrHigher = version >= 3;
211-
}
212-
} catch (NumberFormatException e) {
213-
// If parsing fails, use default behavior
214-
}
215-
}
216-
217194
// Apply different logic based on model version
218-
if (isQwenVersionThreeOrHigher) {
195+
if (ParamUtils.isQwenVersionThreeOrHigher(getModel())) {
219196
if (incrementalOutput != null) {
220197
params.put("incremental_output", incrementalOutput);
221198
}

src/main/java/com/alibaba/dashscope/aigc/multimodalconversation/MultiModalConversationParam.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.alibaba.dashscope.tools.ToolBase;
77
import com.alibaba.dashscope.utils.ApiKeywords;
88
import com.alibaba.dashscope.utils.JsonUtils;
9+
import com.alibaba.dashscope.utils.ParamUtils;
910
import com.google.gson.JsonObject;
1011
import java.nio.ByteBuffer;
1112
import java.util.HashMap;
@@ -225,8 +226,15 @@ public Map<String, Object> getParameters() {
225226
params.put(ApiKeywords.PRESENCE_PENALTY, presencePenalty);
226227
}
227228

228-
if (incrementalOutput) {
229-
params.put(ApiKeywords.INCREMENTAL_OUTPUT, incrementalOutput);
229+
// Apply different logic based on model version
230+
if (ParamUtils.isQwenVersionThreeOrHigher(getModel())) {
231+
if (incrementalOutput != null) {
232+
params.put(ApiKeywords.INCREMENTAL_OUTPUT, incrementalOutput);
233+
}
234+
} else {
235+
if (incrementalOutput) {
236+
params.put(ApiKeywords.INCREMENTAL_OUTPUT, incrementalOutput);
237+
}
230238
}
231239

232240
if (modalities != null) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.alibaba.dashscope.utils;
2+
3+
public class ParamUtils {
4+
5+
/**
6+
* Check if the model is qwen{n} where n >= 3
7+
*
8+
* @param modelName the model name to check
9+
* @return true if model is qwen{n} where n >= 3, false otherwise
10+
*/
11+
public static boolean isQwenVersionThreeOrHigher(String modelName) {
12+
if (modelName == null) {
13+
return false;
14+
}
15+
16+
String lowerModelName = modelName.toLowerCase();
17+
if (!lowerModelName.startsWith("qwen")) {
18+
return false;
19+
}
20+
21+
String remaining = lowerModelName.substring(4);
22+
try {
23+
// Extract the number after "qwen"
24+
StringBuilder numberStr = new StringBuilder();
25+
for (char c : remaining.toCharArray()) {
26+
if (Character.isDigit(c)) {
27+
numberStr.append(c);
28+
} else {
29+
break;
30+
}
31+
}
32+
if (numberStr.length() > 0) {
33+
int version = Integer.parseInt(numberStr.toString());
34+
return version >= 3;
35+
}
36+
} catch (NumberFormatException e) {
37+
// If parsing fails, use default behavior
38+
}
39+
40+
return false;
41+
}
42+
}

0 commit comments

Comments
 (0)