Skip to content

Commit 852c077

Browse files
Add Anthropic Claude Sonnet 5 API support (#988)
1 parent 06acbf4 commit 852c077

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/config/index.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const claudeApiModelKeys = [
8383
'claudeOpus48Api',
8484
'claudeSonnet45Api',
8585
'claudeSonnet46Api',
86+
'claudeSonnet5Api',
8687
'claudeHaiku45Api',
8788
]
8889
export const chatglmApiModelKeys = [
@@ -318,6 +319,10 @@ export const Models = {
318319
value: 'claude-sonnet-4-6',
319320
desc: 'Anthropic (Claude Sonnet 4.6)',
320321
},
322+
claudeSonnet5Api: {
323+
value: 'claude-sonnet-5',
324+
desc: 'Anthropic (Claude Sonnet 5)',
325+
},
321326
claudeHaiku45Api: {
322327
value: 'claude-haiku-4-5-20251001',
323328
desc: 'Anthropic (Claude Haiku 4.5)',

src/services/apis/claude-api.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
66
import { getModelValue } from '../../utils/model-name-convert.mjs'
77

88
function shouldOmitTemperature(model) {
9-
return model === 'claude-opus-4-7' || model === 'claude-opus-4-8'
9+
return model === 'claude-opus-4-7' || model === 'claude-opus-4-8' || model === 'claude-sonnet-5'
10+
}
11+
12+
function shouldDisableDefaultThinking(model) {
13+
return model === 'claude-sonnet-5'
1014
}
1115

1216
/**
@@ -32,6 +36,9 @@ export async function generateAnswersWithClaudeApi(port, question, session) {
3236
stream: true,
3337
max_tokens: config.maxResponseTokenLength,
3438
}
39+
if (shouldDisableDefaultThinking(model)) {
40+
body.thinking = { type: 'disabled' }
41+
}
3542
if (!shouldOmitTemperature(model)) {
3643
body.temperature = config.temperature
3744
}

tests/unit/services/apis/claude-api.test.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ test('claude-api: keeps temperature for Opus 4.6', async (t) => {
119119
assert.equal(body.stream, true)
120120
})
121121

122-
test('claude-api: omits temperature for Opus 4.7 and 4.8', async (t) => {
122+
test('claude-api: omits temperature for models that reject custom sampling', async (t) => {
123123
t.mock.method(console, 'debug', () => {})
124124

125125
for (const [modelName, model] of [
126126
['claudeOpus47Api', 'claude-opus-4-7'],
127127
['claudeOpus48Api', 'claude-opus-4-8'],
128+
['claudeSonnet5Api', 'claude-sonnet-5'],
128129
]) {
129130
await t.test(modelName, async (t) => {
130131
setStorage({
@@ -158,6 +159,11 @@ test('claude-api: omits temperature for Opus 4.7 and 4.8', async (t) => {
158159
assert.equal(body.max_tokens, 1024)
159160
assert.equal(body.stream, true)
160161
assert.equal(Object.hasOwn(body, 'temperature'), false)
162+
if (model === 'claude-sonnet-5') {
163+
assert.deepEqual(body.thinking, { type: 'disabled' })
164+
} else {
165+
assert.equal(Object.hasOwn(body, 'thinking'), false)
166+
}
161167
})
162168
}
163169
})

0 commit comments

Comments
 (0)