Skip to content

Commit 01a9ab0

Browse files
Jonny-chinaxuanqi-coder0xToshii
authored
feat: add all qwen3 models support and add thinking mode options (RooCodeInc#3692)
* feat: add all qwen3 models support and add thinking mode options * fix: qwen model reasoning logic configuration, set the qwen model maxBudget value * fix: correct the maxTokens in qwen3 model * vertex model --------- Co-authored-by: xuanqi <[email protected]> Co-authored-by: 0xtoshii <[email protected]>
1 parent 51a5383 commit 01a9ab0

File tree

4 files changed

+302
-35
lines changed

4 files changed

+302
-35
lines changed

.changeset/chatty-books-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
add all qwen3 models support and add thinking mode options

src/api/providers/qwen.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,37 @@ export class QwenHandler implements ApiHandler {
5353
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
5454
const model = this.getModel()
5555
const isDeepseekReasoner = model.id.includes("deepseek-r1")
56+
const isReasoningModelFamily = model.id.includes("qwen3") || ["qwen-plus-latest", "qwen-turbo-latest"].includes(model.id)
57+
5658
let openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
5759
{ role: "system", content: systemPrompt },
5860
...convertToOpenAiMessages(messages),
5961
]
60-
if (isDeepseekReasoner) {
62+
63+
let temperature: number | undefined = 0
64+
// Configuration for extended thinking
65+
const budgetTokens = this.options.thinkingBudgetTokens || 0
66+
const reasoningOn = budgetTokens !== 0 ? true : false
67+
const thinkingArgs = isReasoningModelFamily
68+
? {
69+
enable_thinking: reasoningOn,
70+
thinking_budget: reasoningOn ? budgetTokens : undefined,
71+
}
72+
: undefined
73+
74+
if (isDeepseekReasoner || (reasoningOn && isReasoningModelFamily)) {
6175
openAiMessages = convertToR1Format([{ role: "user", content: systemPrompt }, ...messages])
76+
temperature = undefined
6277
}
78+
6379
const stream = await this.client.chat.completions.create({
6480
model: model.id,
6581
max_completion_tokens: model.info.maxTokens,
6682
messages: openAiMessages,
6783
stream: true,
6884
stream_options: { include_usage: true },
69-
...(model.id === "deepseek-r1" ? {} : { temperature: 0 }),
85+
temperature,
86+
...thinkingArgs,
7087
})
7188

7289
for await (const chunk of stream) {

src/shared/api.ts

Lines changed: 254 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,118 @@ export type InternationalQwenModelId = keyof typeof internationalQwenModels
10211021
export const internationalQwenDefaultModelId: InternationalQwenModelId = "qwen-coder-plus-latest"
10221022
export const mainlandQwenDefaultModelId: MainlandQwenModelId = "qwen-coder-plus-latest"
10231023
export const internationalQwenModels = {
1024+
"qwen3-235b-a22b": {
1025+
maxTokens: 16_384,
1026+
contextWindow: 131_072,
1027+
supportsImages: false,
1028+
supportsPromptCache: false,
1029+
inputPrice: 2,
1030+
outputPrice: 8,
1031+
cacheWritesPrice: 2,
1032+
cacheReadsPrice: 8,
1033+
thinkingConfig: {
1034+
maxBudget: 38_912,
1035+
outputPrice: 20,
1036+
},
1037+
},
1038+
"qwen3-32b": {
1039+
maxTokens: 16_384,
1040+
contextWindow: 131_072,
1041+
supportsImages: false,
1042+
supportsPromptCache: false,
1043+
inputPrice: 2,
1044+
outputPrice: 8,
1045+
cacheWritesPrice: 2,
1046+
cacheReadsPrice: 8,
1047+
thinkingConfig: {
1048+
maxBudget: 38_912,
1049+
outputPrice: 20,
1050+
},
1051+
},
1052+
"qwen3-30b-a3b": {
1053+
maxTokens: 16_384,
1054+
contextWindow: 131_072,
1055+
supportsImages: false,
1056+
supportsPromptCache: false,
1057+
inputPrice: 0.75,
1058+
outputPrice: 3,
1059+
cacheWritesPrice: 0.75,
1060+
cacheReadsPrice: 3,
1061+
thinkingConfig: {
1062+
maxBudget: 38_912,
1063+
outputPrice: 7.5,
1064+
},
1065+
},
1066+
"qwen3-14b": {
1067+
maxTokens: 8_192,
1068+
contextWindow: 131_072,
1069+
supportsImages: false,
1070+
supportsPromptCache: false,
1071+
inputPrice: 1,
1072+
outputPrice: 4,
1073+
cacheWritesPrice: 1,
1074+
cacheReadsPrice: 4,
1075+
thinkingConfig: {
1076+
maxBudget: 38_912,
1077+
outputPrice: 10,
1078+
},
1079+
},
1080+
"qwen3-8b": {
1081+
maxTokens: 8_192,
1082+
contextWindow: 131_072,
1083+
supportsImages: false,
1084+
supportsPromptCache: false,
1085+
inputPrice: 0.5,
1086+
outputPrice: 2,
1087+
cacheWritesPrice: 0.5,
1088+
cacheReadsPrice: 2,
1089+
thinkingConfig: {
1090+
maxBudget: 38_912,
1091+
outputPrice: 5,
1092+
},
1093+
},
1094+
"qwen3-4b": {
1095+
maxTokens: 8_192,
1096+
contextWindow: 131_072,
1097+
supportsImages: false,
1098+
supportsPromptCache: false,
1099+
inputPrice: 0.3,
1100+
outputPrice: 1.2,
1101+
cacheWritesPrice: 0.3,
1102+
cacheReadsPrice: 1.2,
1103+
thinkingConfig: {
1104+
maxBudget: 38_912,
1105+
outputPrice: 3,
1106+
},
1107+
},
1108+
"qwen3-1.7b": {
1109+
maxTokens: 8_192,
1110+
contextWindow: 32_768,
1111+
supportsImages: false,
1112+
supportsPromptCache: false,
1113+
inputPrice: 0.3,
1114+
outputPrice: 1.2,
1115+
cacheWritesPrice: 0.3,
1116+
cacheReadsPrice: 1.2,
1117+
thinkingConfig: {
1118+
maxBudget: 30_720,
1119+
outputPrice: 3,
1120+
},
1121+
},
1122+
"qwen3-0.6b": {
1123+
maxTokens: 8_192,
1124+
contextWindow: 32_768,
1125+
supportsImages: false,
1126+
supportsPromptCache: false,
1127+
inputPrice: 0.3,
1128+
outputPrice: 1.2,
1129+
cacheWritesPrice: 0.3,
1130+
cacheReadsPrice: 1.2,
1131+
thinkingConfig: {
1132+
maxBudget: 30_720,
1133+
outputPrice: 3,
1134+
},
1135+
},
10241136
"qwen2.5-coder-32b-instruct": {
10251137
maxTokens: 8_192,
10261138
contextWindow: 131_072,
@@ -1092,24 +1204,32 @@ export const internationalQwenModels = {
10921204
cacheReadsPrice: 7,
10931205
},
10941206
"qwen-plus-latest": {
1095-
maxTokens: 129_024,
1207+
maxTokens: 16_384,
10961208
contextWindow: 131_072,
10971209
supportsImages: false,
10981210
supportsPromptCache: false,
10991211
inputPrice: 0.8,
11001212
outputPrice: 2,
11011213
cacheWritesPrice: 0.8,
1102-
cacheReadsPrice: 0.2,
1214+
cacheReadsPrice: 2,
1215+
thinkingConfig: {
1216+
maxBudget: 38_912,
1217+
outputPrice: 16,
1218+
},
11031219
},
11041220
"qwen-turbo-latest": {
1105-
maxTokens: 1_000_000,
1221+
maxTokens: 16_384,
11061222
contextWindow: 1_000_000,
11071223
supportsImages: false,
11081224
supportsPromptCache: false,
1109-
inputPrice: 0.8,
1110-
outputPrice: 2,
1111-
cacheWritesPrice: 0.8,
1112-
cacheReadsPrice: 2,
1225+
inputPrice: 0.3,
1226+
outputPrice: 0.6,
1227+
cacheWritesPrice: 0.3,
1228+
cacheReadsPrice: 0.6,
1229+
thinkingConfig: {
1230+
maxBudget: 38_912,
1231+
outputPrice: 6,
1232+
},
11131233
},
11141234
"qwen-max-latest": {
11151235
maxTokens: 30_720,
@@ -1224,6 +1344,118 @@ export const internationalQwenModels = {
12241344
} as const satisfies Record<string, ModelInfo>
12251345

12261346
export const mainlandQwenModels = {
1347+
"qwen3-235b-a22b": {
1348+
maxTokens: 16_384,
1349+
contextWindow: 131_072,
1350+
supportsImages: false,
1351+
supportsPromptCache: false,
1352+
inputPrice: 2,
1353+
outputPrice: 8,
1354+
cacheWritesPrice: 2,
1355+
cacheReadsPrice: 8,
1356+
thinkingConfig: {
1357+
maxBudget: 38_912,
1358+
outputPrice: 20,
1359+
},
1360+
},
1361+
"qwen3-32b": {
1362+
maxTokens: 16_384,
1363+
contextWindow: 131_072,
1364+
supportsImages: false,
1365+
supportsPromptCache: false,
1366+
inputPrice: 2,
1367+
outputPrice: 8,
1368+
cacheWritesPrice: 2,
1369+
cacheReadsPrice: 8,
1370+
thinkingConfig: {
1371+
maxBudget: 38_912,
1372+
outputPrice: 20,
1373+
},
1374+
},
1375+
"qwen3-30b-a3b": {
1376+
maxTokens: 16_384,
1377+
contextWindow: 131_072,
1378+
supportsImages: false,
1379+
supportsPromptCache: false,
1380+
inputPrice: 0.75,
1381+
outputPrice: 3,
1382+
cacheWritesPrice: 0.75,
1383+
cacheReadsPrice: 3,
1384+
thinkingConfig: {
1385+
maxBudget: 38_912,
1386+
outputPrice: 7.5,
1387+
},
1388+
},
1389+
"qwen3-14b": {
1390+
maxTokens: 8_192,
1391+
contextWindow: 131_072,
1392+
supportsImages: false,
1393+
supportsPromptCache: false,
1394+
inputPrice: 1,
1395+
outputPrice: 4,
1396+
cacheWritesPrice: 1,
1397+
cacheReadsPrice: 4,
1398+
thinkingConfig: {
1399+
maxBudget: 38_912,
1400+
outputPrice: 10,
1401+
},
1402+
},
1403+
"qwen3-8b": {
1404+
maxTokens: 8_192,
1405+
contextWindow: 131_072,
1406+
supportsImages: false,
1407+
supportsPromptCache: false,
1408+
inputPrice: 0.5,
1409+
outputPrice: 2,
1410+
cacheWritesPrice: 0.5,
1411+
cacheReadsPrice: 2,
1412+
thinkingConfig: {
1413+
maxBudget: 38_912,
1414+
outputPrice: 5,
1415+
},
1416+
},
1417+
"qwen3-4b": {
1418+
maxTokens: 8_192,
1419+
contextWindow: 131_072,
1420+
supportsImages: false,
1421+
supportsPromptCache: false,
1422+
inputPrice: 0.3,
1423+
outputPrice: 1.2,
1424+
cacheWritesPrice: 0.3,
1425+
cacheReadsPrice: 1.2,
1426+
thinkingConfig: {
1427+
maxBudget: 38_912,
1428+
outputPrice: 3,
1429+
},
1430+
},
1431+
"qwen3-1.7b": {
1432+
maxTokens: 8_192,
1433+
contextWindow: 32_768,
1434+
supportsImages: false,
1435+
supportsPromptCache: false,
1436+
inputPrice: 0.3,
1437+
outputPrice: 1.2,
1438+
cacheWritesPrice: 0.3,
1439+
cacheReadsPrice: 1.2,
1440+
thinkingConfig: {
1441+
maxBudget: 30_720,
1442+
outputPrice: 3,
1443+
},
1444+
},
1445+
"qwen3-0.6b": {
1446+
maxTokens: 8_192,
1447+
contextWindow: 32_768,
1448+
supportsImages: false,
1449+
supportsPromptCache: false,
1450+
inputPrice: 0.3,
1451+
outputPrice: 1.2,
1452+
cacheWritesPrice: 0.3,
1453+
cacheReadsPrice: 1.2,
1454+
thinkingConfig: {
1455+
maxBudget: 30_720,
1456+
outputPrice: 3,
1457+
},
1458+
},
12271459
"qwen2.5-coder-32b-instruct": {
12281460
maxTokens: 8_192,
12291461
contextWindow: 131_072,
@@ -1295,24 +1527,32 @@ export const mainlandQwenModels = {
12951527
cacheReadsPrice: 7,
12961528
},
12971529
"qwen-plus-latest": {
1298-
maxTokens: 129_024,
1530+
maxTokens: 16_384,
12991531
contextWindow: 131_072,
13001532
supportsImages: false,
13011533
supportsPromptCache: false,
13021534
inputPrice: 0.8,
13031535
outputPrice: 2,
13041536
cacheWritesPrice: 0.8,
1305-
cacheReadsPrice: 0.2,
1537+
cacheReadsPrice: 2,
1538+
thinkingConfig: {
1539+
maxBudget: 38_912,
1540+
outputPrice: 16,
1541+
},
13061542
},
13071543
"qwen-turbo-latest": {
1308-
maxTokens: 1_000_000,
1544+
maxTokens: 16_384,
13091545
contextWindow: 1_000_000,
13101546
supportsImages: false,
13111547
supportsPromptCache: false,
1312-
inputPrice: 0.8,
1313-
outputPrice: 2,
1314-
cacheWritesPrice: 0.8,
1315-
cacheReadsPrice: 2,
1548+
inputPrice: 0.3,
1549+
outputPrice: 0.6,
1550+
cacheWritesPrice: 0.3,
1551+
cacheReadsPrice: 0.6,
1552+
thinkingConfig: {
1553+
maxBudget: 38_912,
1554+
outputPrice: 6,
1555+
},
13161556
},
13171557
"qwen-max-latest": {
13181558
maxTokens: 30_720,

0 commit comments

Comments
 (0)