Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const claudeApiModelKeys = [
'claudeOpus48Api',
'claudeSonnet45Api',
'claudeSonnet46Api',
'claudeSonnet5Api',
'claudeHaiku45Api',
]
export const chatglmApiModelKeys = [
Expand Down Expand Up @@ -318,6 +319,10 @@ export const Models = {
value: 'claude-sonnet-4-6',
desc: 'Anthropic (Claude Sonnet 4.6)',
},
claudeSonnet5Api: {
value: 'claude-sonnet-5',
desc: 'Anthropic (Claude Sonnet 5)',
},
claudeHaiku45Api: {
value: 'claude-haiku-4-5-20251001',
desc: 'Anthropic (Claude Haiku 4.5)',
Expand Down
9 changes: 8 additions & 1 deletion src/services/apis/claude-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { getConversationPairs } from '../../utils/get-conversation-pairs.mjs'
import { getModelValue } from '../../utils/model-name-convert.mjs'

function shouldOmitTemperature(model) {
return model === 'claude-opus-4-7' || model === 'claude-opus-4-8'
return model === 'claude-opus-4-7' || model === 'claude-opus-4-8' || model === 'claude-sonnet-5'
}

function shouldDisableDefaultThinking(model) {
return model === 'claude-sonnet-5'
}
Comment thread
PeterDaveHello marked this conversation as resolved.

/**
Expand All @@ -32,6 +36,9 @@ export async function generateAnswersWithClaudeApi(port, question, session) {
stream: true,
max_tokens: config.maxResponseTokenLength,
}
if (shouldDisableDefaultThinking(model)) {
body.thinking = { type: 'disabled' }
}
Comment thread
PeterDaveHello marked this conversation as resolved.
if (!shouldOmitTemperature(model)) {
body.temperature = config.temperature
}
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/services/apis/claude-api.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ test('claude-api: keeps temperature for Opus 4.6', async (t) => {
assert.equal(body.stream, true)
})

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

for (const [modelName, model] of [
['claudeOpus47Api', 'claude-opus-4-7'],
['claudeOpus48Api', 'claude-opus-4-8'],
['claudeSonnet5Api', 'claude-sonnet-5'],
]) {
await t.test(modelName, async (t) => {
setStorage({
Expand Down Expand Up @@ -158,6 +159,11 @@ test('claude-api: omits temperature for Opus 4.7 and 4.8', async (t) => {
assert.equal(body.max_tokens, 1024)
assert.equal(body.stream, true)
assert.equal(Object.hasOwn(body, 'temperature'), false)
if (model === 'claude-sonnet-5') {
assert.deepEqual(body.thinking, { type: 'disabled' })
} else {
assert.equal(Object.hasOwn(body, 'thinking'), false)
}
Comment thread
PeterDaveHello marked this conversation as resolved.
})
}
})
Expand Down