feat: add isClaude45ReasoningModel function and update getTopP logic (#10988)

* feat: add isClaude45ReasoningModel function and update getTopP logic

* fix: update getTopP logic to correctly handle Claude45 model support

* fix: update getTemperature and getTopP logic to handle Claude45 model conditions

* fix: update getTemperature logic to correctly handle Claude45 model conditions
fix: refine isClaude45ReasoningModel regex pattern for better matching

(cherry picked from commit 250f59234b)
This commit is contained in:
SuYao 2025-10-27 20:34:11 +08:00 committed by dev
parent c2a78b4129
commit cd26190fe9
2 changed files with 15 additions and 2 deletions

View File

@ -4,6 +4,7 @@
*/
import {
isClaude45ReasoningModel,
isClaudeReasoningModel,
isNotSupportTemperatureAndTopP,
isSupportedFlexServiceTier
@ -19,7 +20,10 @@ export function getTemperature(assistant: Assistant, model: Model): number | und
if (assistant.settings?.reasoning_effort && isClaudeReasoningModel(model)) {
return undefined
}
if (isNotSupportTemperatureAndTopP(model)) {
if (
isNotSupportTemperatureAndTopP(model) ||
(isClaude45ReasoningModel(model) && assistant.settings?.enableTopP && !assistant.settings?.enableTemperature)
) {
return undefined
}
const assistantSettings = getAssistantSettings(assistant)
@ -33,7 +37,10 @@ export function getTopP(assistant: Assistant, model: Model): number | undefined
if (assistant.settings?.reasoning_effort && isClaudeReasoningModel(model)) {
return undefined
}
if (isNotSupportTemperatureAndTopP(model)) {
if (
isNotSupportTemperatureAndTopP(model) ||
(isClaude45ReasoningModel(model) && assistant.settings?.enableTemperature)
) {
return undefined
}
const assistantSettings = getAssistantSettings(assistant)

View File

@ -342,6 +342,12 @@ export function isSupportedThinkingTokenDoubaoModel(model?: Model): boolean {
return DOUBAO_THINKING_MODEL_REGEX.test(modelId) || DOUBAO_THINKING_MODEL_REGEX.test(model.name)
}
export function isClaude45ReasoningModel(model: Model): boolean {
const modelId = getLowerBaseModelName(model.id, '/')
const regex = /claude-(sonnet|opus|haiku)-4(-|.)5(?:-[\w-]+)?$/i
return regex.test(modelId)
}
export function isClaudeReasoningModel(model?: Model): boolean {
if (!model) {
return false