Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
76 lines (71 loc) · 2.94 KB

File metadata and controls

76 lines (71 loc) · 2.94 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Alibaba, Inc. and its affiliates.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
public class GenerationCallEarlyStop {
static String modelName = Generation.Models.QWEN_PLUS;
public static void stopWithTokens()
throws NoApiKeyException, ApiException, InputRequiredException {
Generation gen = new Generation();
List<Message> msgManager = new ArrayList<>();
Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("怎么做西红柿炖牛腩好吃").build();
msgManager.add(systemMsg);
msgManager.add(userMsg);
// 老抽 [91777, 99950]
// 葱花 [102902, 99232]
QwenParam param = QwenParam.builder().model(modelName).messages(msgManager)
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.topP(0.8)
.enableSearch(true)
.stopToken(Arrays.asList(91777, 99950))
.stopToken(Arrays.asList(102902, 99232))
.build();
GenerationResult result = gen.call(param);
System.out.println(result);
param.setStopTokens(Arrays.asList(Arrays.asList(102902)));
result = gen.call(param);
System.out.println(result);
}
public static void stopWithStrings()
throws NoApiKeyException, ApiException, InputRequiredException {
Generation gen = new Generation();
List<Message> msgManager = new ArrayList<>();
Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("怎么做西红柿炖牛腩好吃").build();
msgManager.add(systemMsg);
msgManager.add(userMsg);
// 老抽 [91777, 99950]
// 葱花 [102902, 99232]
QwenParam param = QwenParam.builder().model(modelName).messages(msgManager)
.resultFormat(QwenParam.ResultFormat.MESSAGE)
.topP(0.8)
.enableSearch(true)
.stopString("老抽")
.stopString("葱花")
.build();
GenerationResult result = gen.call(param);
System.out.println(result);
param.setStopStrings(Arrays.asList("葱花"));
;
result = gen.call(param);
System.out.println(result);
}
public static void main(String[] args) {
try {
stopWithTokens();
stopWithStrings();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.