From 542ce36a80ec6f4f8651ea260ca0ba7c6890d2f0 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 2 Mar 2025 17:12:51 -0800 Subject: [PATCH] Fix issue where thinking param was being sent with non-claude 3.7 models --- src/api/providers/anthropic.ts | 6 ++++-- src/api/providers/bedrock.ts | 5 +++-- src/api/providers/vertex.ts | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/providers/anthropic.ts b/src/api/providers/anthropic.ts index 93804d99c2..67e1425482 100644 --- a/src/api/providers/anthropic.ts +++ b/src/api/providers/anthropic.ts @@ -19,11 +19,13 @@ export class AnthropicHandler implements ApiHandler { @withRetry() async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream { - let budget_tokens = this.options.thinkingBudgetTokens || 0 - const reasoningOn = budget_tokens !== 0 ? true : false const model = this.getModel() let stream: AnthropicStream const modelId = model.id + + let budget_tokens = this.options.thinkingBudgetTokens || 0 + const reasoningOn = modelId.includes("3-7") && budget_tokens !== 0 ? true : false + switch (modelId) { // 'latest' alias does not support cache_control case "claude-3-7-sonnet-20250219": diff --git a/src/api/providers/bedrock.ts b/src/api/providers/bedrock.ts index aee2363fe9..7d2ce21a7f 100644 --- a/src/api/providers/bedrock.ts +++ b/src/api/providers/bedrock.ts @@ -16,11 +16,12 @@ export class AwsBedrockHandler implements ApiHandler { @withRetry() async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream { - let budget_tokens = this.options.thinkingBudgetTokens || 0 - const reasoningOn = budget_tokens !== 0 ? true : false // cross region inference requires prefixing the model id with the region let modelId = await this.getModelId() + let budget_tokens = this.options.thinkingBudgetTokens || 0 + const reasoningOn = modelId.includes("3-7") && budget_tokens !== 0 ? true : false + // Get model info and message indices for caching const model = this.getModel() const userMsgIndices = messages.reduce((acc, msg, index) => (msg.role === "user" ? [...acc, index] : acc), [] as number[]) diff --git a/src/api/providers/vertex.ts b/src/api/providers/vertex.ts index 6ef9824875..2ba064cab7 100644 --- a/src/api/providers/vertex.ts +++ b/src/api/providers/vertex.ts @@ -32,7 +32,7 @@ export class VertexHandler implements ApiHandler { if (modelId.includes("claude")) { let budget_tokens = this.options.thinkingBudgetTokens || 0 - const reasoningOn = budget_tokens !== 0 ? true : false + const reasoningOn = modelId.includes("3-7") && budget_tokens !== 0 ? true : false let stream switch (modelId) {