refactor: Improve reasoning effort configuration for Claude models
- Refactored reasoning effort handling for Claude models - Added type definition for ReasoningEffort - Simplified budget token calculation - Improved type safety and readability of the method
This commit is contained in:
parent
13b465fe73
commit
581e2fb786
@ -24,6 +24,8 @@ import {
|
|||||||
import { CompletionsParams } from '.'
|
import { CompletionsParams } from '.'
|
||||||
import BaseProvider from './BaseProvider'
|
import BaseProvider from './BaseProvider'
|
||||||
|
|
||||||
|
type ReasoningEffort = 'high' | 'medium' | 'low'
|
||||||
|
|
||||||
export default class OpenAIProvider extends BaseProvider {
|
export default class OpenAIProvider extends BaseProvider {
|
||||||
private sdk: OpenAI
|
private sdk: OpenAI
|
||||||
|
|
||||||
@ -177,27 +179,26 @@ export default class OpenAIProvider extends BaseProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const effort_ratio =
|
|
||||||
assistant?.settings?.reasoning_effort === 'high'
|
|
||||||
? 0.8
|
|
||||||
: assistant?.settings?.reasoning_effort === 'medium'
|
|
||||||
? 0.5
|
|
||||||
: assistant?.settings?.reasoning_effort === 'low'
|
|
||||||
? 0.2
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
if (model.id.includes('claude-3.7-sonnet') || model.id.includes('claude-3-7-sonnet')) {
|
if (model.id.includes('claude-3.7-sonnet') || model.id.includes('claude-3-7-sonnet')) {
|
||||||
if (!effort_ratio) {
|
const effortRatios: Record<ReasoningEffort, number> = {
|
||||||
return {
|
high: 0.8,
|
||||||
type: 'disabled'
|
medium: 0.5,
|
||||||
}
|
low: 0.2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const effort = assistant?.settings?.reasoning_effort as ReasoningEffort
|
||||||
|
const effortRatio = effortRatios[effort]
|
||||||
|
|
||||||
|
if (!effortRatio) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxTokens = assistant?.settings?.maxTokens || DEFAULT_MAX_TOKENS
|
||||||
|
const budgetTokens = Math.trunc(Math.max(Math.min(maxTokens * effortRatio, 32000), 1024))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
thinking: {
|
thinking: {
|
||||||
budget_tokens: Math.max(
|
budget_tokens: budgetTokens
|
||||||
Math.min((assistant?.settings?.maxTokens || DEFAULT_MAX_TOKENS) * effort_ratio, 32000),
|
|
||||||
1024
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user