mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
fix(OpenAIProvider): enhance token budget calculation in OpenRouter (#5625)
* fix(OpenAIProvider): enhance token budget calculation in OpenRouter * fix(OpenAIProvider): update budget token calculation and adjust effort ratio for improved reasoning support
This commit is contained in:
parent
1111696aab
commit
7456c55974
@ -1,3 +1,4 @@
|
||||
import { DEFAULT_MAX_TOKENS } from '@renderer/config/constant'
|
||||
import {
|
||||
findTokenLimit,
|
||||
getOpenAIWebSearchParams,
|
||||
@ -283,14 +284,13 @@ export default class OpenAIProvider extends BaseProvider {
|
||||
const budgetTokens = Math.floor((findTokenLimit(model.id)?.max || 0) * effortRatio)
|
||||
// OpenRouter models
|
||||
if (model.provider === 'openrouter') {
|
||||
if (isSupportedReasoningEffortModel(model)) {
|
||||
if (isSupportedReasoningEffortModel(model) || isSupportedThinkingTokenClaudeModel(model)) {
|
||||
return {
|
||||
reasoning: {
|
||||
effort: assistant?.settings?.reasoning_effort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isSupportedThinkingTokenModel(model)) {
|
||||
return {
|
||||
reasoning: {
|
||||
@ -323,11 +323,12 @@ export default class OpenAIProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
// Claude models
|
||||
const { maxTokens } = getAssistantSettings(assistant)
|
||||
if (isSupportedThinkingTokenClaudeModel(model)) {
|
||||
return {
|
||||
thinking: {
|
||||
type: 'enabled',
|
||||
budget_tokens: budgetTokens
|
||||
budget_tokens: Math.floor(Math.max(Math.min(budgetTokens, maxTokens || DEFAULT_MAX_TOKENS), 1024))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ export type EffortRatio = Record<ReasoningEffortOptions, number>
|
||||
export const EFFORT_RATIO: EffortRatio = {
|
||||
low: 0.2,
|
||||
medium: 0.5,
|
||||
high: 1,
|
||||
high: 0.8,
|
||||
auto: 2
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user