Skip to content

Commit c9330a3

Browse files
committed
fix(model/chat): invalid increamental_output
1 parent b0ea3f9 commit c9330a3

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

samples/GenerationStreamCall.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ public class GenerationStreamCall {
1616
public static void streamCall()
1717
throws NoApiKeyException, ApiException, InputRequiredException {
1818
Generation gen = new Generation();
19-
GenerationParam param = GenerationParam.builder().model(Generation.Models.QWEN_PLUS)
20-
.prompt("就当前的海洋污染的情况,写一份限塑的倡议书提纲,需要有理有据地号召大家克制地使用塑料制品").topP(0.8).build();
19+
GenerationParam param = GenerationParam.builder()
20+
.model("qwen3-max")
21+
.prompt("就当前的海洋污染的情况,写一份限塑的倡议书提纲,需要有理有据地号召大家克制地使用塑料制品")
22+
.topP(0.8)
23+
.incrementalOutput(false)
24+
.build();
2125
Flowable<GenerationResult> result = gen.streamCall(param);
2226
result.blockingForEach(message -> {
2327
System.out.println(JsonUtils.toJson(message));

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,41 @@ public Map<String, Object> getParameters() {
190190
if (temperature != null) {
191191
params.put("temperature", temperature);
192192
}
193-
if (incrementalOutput) {
194-
params.put("incremental_output", incrementalOutput);
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+
}
195215
}
216+
217+
// Apply different logic based on model version
218+
if (isQwenVersionThreeOrHigher) {
219+
if (incrementalOutput != null) {
220+
params.put("incremental_output", incrementalOutput);
221+
}
222+
} else {
223+
if (incrementalOutput) {
224+
params.put("incremental_output", incrementalOutput);
225+
}
226+
}
227+
196228
if (repetitionPenalty != null) {
197229
params.put(REPETITION_PENALTY, repetitionPenalty);
198230
}

0 commit comments

Comments
 (0)