Browse Source

Fix budgetTokens

cte 10 months ago
parent
commit
33fd3bd6b3
2 changed files with 4 additions and 6 deletions
  1. 1 1
      src/api/providers/anthropic.ts
  2. 3 5
      src/api/providers/openrouter.ts

+ 1 - 1
src/api/providers/anthropic.ts

@@ -32,7 +32,6 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {
 		const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
 		const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
 		let { id: modelId, info: modelInfo } = this.getModel()
 		let { id: modelId, info: modelInfo } = this.getModel()
 		const maxTokens = modelInfo.maxTokens || 8192
 		const maxTokens = modelInfo.maxTokens || 8192
-		const budgetTokens = this.options.anthropicThinking ?? Math.min(maxTokens - 1, 8192)
 		let temperature = this.options.modelTemperature ?? ANTHROPIC_DEFAULT_TEMPERATURE
 		let temperature = this.options.modelTemperature ?? ANTHROPIC_DEFAULT_TEMPERATURE
 		let thinking: BetaThinkingConfigParam | undefined = undefined
 		let thinking: BetaThinkingConfigParam | undefined = undefined
 
 
@@ -42,6 +41,7 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {
 			// `claude-3-7-sonnet-20250219` model with a thinking budget.
 			// `claude-3-7-sonnet-20250219` model with a thinking budget.
 			// We can handle this more elegantly in the future.
 			// We can handle this more elegantly in the future.
 			modelId = "claude-3-7-sonnet-20250219"
 			modelId = "claude-3-7-sonnet-20250219"
+			const budgetTokens = this.options.anthropicThinking ?? Math.max(maxTokens * 0.8, 1024)
 			thinking = { type: "enabled", budget_tokens: budgetTokens }
 			thinking = { type: "enabled", budget_tokens: budgetTokens }
 			temperature = 1.0
 			temperature = 1.0
 		}
 		}

+ 3 - 5
src/api/providers/openrouter.ts

@@ -109,13 +109,11 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
 		}
 		}
 
 
 		let temperature = this.options.modelTemperature ?? defaultTemperature
 		let temperature = this.options.modelTemperature ?? defaultTemperature
-
-		const maxTokens = modelInfo.maxTokens
-		const budgetTokens = this.options.anthropicThinking ?? Math.min((maxTokens ?? 8192) - 1, 8192)
 		let thinking: BetaThinkingConfigParam | undefined = undefined
 		let thinking: BetaThinkingConfigParam | undefined = undefined
 
 
-		// Anthropic "Thinking" models require a temperature of 1.0.
 		if (modelInfo.thinking) {
 		if (modelInfo.thinking) {
+			const maxTokens = modelInfo.maxTokens || 8192
+			const budgetTokens = this.options.anthropicThinking ?? Math.max(maxTokens * 0.8, 1024)
 			thinking = { type: "enabled", budget_tokens: budgetTokens }
 			thinking = { type: "enabled", budget_tokens: budgetTokens }
 			temperature = 1.0
 			temperature = 1.0
 		}
 		}
@@ -125,7 +123,7 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
 
 
 		const completionParams: OpenRouterChatCompletionParams = {
 		const completionParams: OpenRouterChatCompletionParams = {
 			model: modelId,
 			model: modelId,
-			max_tokens: maxTokens,
+			max_tokens: modelInfo.maxTokens,
 			temperature,
 			temperature,
 			thinking, // OpenRouter is temporarily supporting this.
 			thinking, // OpenRouter is temporarily supporting this.
 			top_p: topP,
 			top_p: topP,