Skip to content

Commit 33fd3bd

Browse files
committed
Fix budgetTokens
1 parent 8971e47 commit 33fd3bd

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/api/providers/anthropic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {
3232
const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
3333
let { id: modelId, info: modelInfo } = this.getModel()
3434
const maxTokens = modelInfo.maxTokens || 8192
35-
const budgetTokens = this.options.anthropicThinking ?? Math.min(maxTokens - 1, 8192)
3635
let temperature = this.options.modelTemperature ?? ANTHROPIC_DEFAULT_TEMPERATURE
3736
let thinking: BetaThinkingConfigParam | undefined = undefined
3837

@@ -42,6 +41,7 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {
4241
// `claude-3-7-sonnet-20250219` model with a thinking budget.
4342
// We can handle this more elegantly in the future.
4443
modelId = "claude-3-7-sonnet-20250219"
44+
const budgetTokens = this.options.anthropicThinking ?? Math.max(maxTokens * 0.8, 1024)
4545
thinking = { type: "enabled", budget_tokens: budgetTokens }
4646
temperature = 1.0
4747
}

src/api/providers/openrouter.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
109109
}
110110

111111
let temperature = this.options.modelTemperature ?? defaultTemperature
112-
113-
const maxTokens = modelInfo.maxTokens
114-
const budgetTokens = this.options.anthropicThinking ?? Math.min((maxTokens ?? 8192) - 1, 8192)
115112
let thinking: BetaThinkingConfigParam | undefined = undefined
116113

117-
// Anthropic "Thinking" models require a temperature of 1.0.
118114
if (modelInfo.thinking) {
115+
const maxTokens = modelInfo.maxTokens || 8192
116+
const budgetTokens = this.options.anthropicThinking ?? Math.max(maxTokens * 0.8, 1024)
119117
thinking = { type: "enabled", budget_tokens: budgetTokens }
120118
temperature = 1.0
121119
}
@@ -125,7 +123,7 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
125123

126124
const completionParams: OpenRouterChatCompletionParams = {
127125
model: modelId,
128-
max_tokens: maxTokens,
126+
max_tokens: modelInfo.maxTokens,
129127
temperature,
130128
thinking, // OpenRouter is temporarily supporting this.
131129
top_p: topP,

0 commit comments

Comments
 (0)