Explorar o código

Merge pull request #1262 from RooVetGit/cte/lower-default-max-tokens

Fix maxTokens defaults for Claude 3.7 Sonnet models
Chris Estreich hai 10 meses
pai
achega
390932ea68

+ 5 - 0
.changeset/tasty-grapes-suffer.md

@@ -0,0 +1,5 @@
+---
+"roo-cline": patch
+---
+
+Fix maxTokens defaults for Claude 3.7 Sonnet models

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

@@ -278,7 +278,7 @@ export async function getOpenRouterModels() {
 					modelInfo.supportsPromptCache = true
 					modelInfo.cacheWritesPrice = 3.75
 					modelInfo.cacheReadsPrice = 0.3
-					modelInfo.maxTokens = 64_000
+					modelInfo.maxTokens = rawModel.id === "anthropic/claude-3.7-sonnet:thinking" ? 64_000 : 16_384
 					break
 				case rawModel.id.startsWith("anthropic/claude-3.5-sonnet-20240620"):
 					modelInfo.supportsPromptCache = true

+ 3 - 3
src/shared/api.ts

@@ -111,7 +111,7 @@ export const anthropicModels = {
 		thinking: true,
 	},
 	"claude-3-7-sonnet-20250219": {
-		maxTokens: 64_000,
+		maxTokens: 16_384,
 		contextWindow: 200_000,
 		supportsImages: true,
 		supportsComputerUse: true,
@@ -437,7 +437,7 @@ export type VertexModelId = keyof typeof vertexModels
 export const vertexDefaultModelId: VertexModelId = "claude-3-7-sonnet@20250219"
 export const vertexModels = {
 	"claude-3-7-sonnet@20250219:thinking": {
-		maxTokens: 64000,
+		maxTokens: 64_000,
 		contextWindow: 200_000,
 		supportsImages: true,
 		supportsComputerUse: true,
@@ -449,7 +449,7 @@ export const vertexModels = {
 		thinking: true,
 	},
 	"claude-3-7-sonnet@20250219": {
-		maxTokens: 8192,
+		maxTokens: 16_384,
 		contextWindow: 200_000,
 		supportsImages: true,
 		supportsComputerUse: true,

+ 0 - 2
webview-ui/src/components/settings/ApiOptions.tsx

@@ -7,7 +7,6 @@ import * as vscodemodels from "vscode"
 import {
 	ApiConfiguration,
 	ModelInfo,
-	ApiProvider,
 	anthropicDefaultModelId,
 	anthropicModels,
 	azureOpenAiDefaultApiVersion,
@@ -1385,7 +1384,6 @@ const ApiOptions = ({
 						apiConfiguration={apiConfiguration}
 						setApiConfigurationField={setApiConfigurationField}
 						modelInfo={selectedModelInfo}
-						provider={selectedProvider as ApiProvider}
 					/>
 					<ModelInfoView
 						selectedModelId={selectedModelId}

+ 3 - 9
webview-ui/src/components/settings/ThinkingBudget.tsx

@@ -1,5 +1,5 @@
 import { useEffect, useMemo } from "react"
-import { ApiProvider } from "../../../../src/shared/api"
+
 import { Slider } from "@/components/ui"
 
 import { ApiConfiguration, ModelInfo } from "../../../../src/shared/api"
@@ -8,16 +8,10 @@ interface ThinkingBudgetProps {
 	apiConfiguration: ApiConfiguration
 	setApiConfigurationField: <K extends keyof ApiConfiguration>(field: K, value: ApiConfiguration[K]) => void
 	modelInfo?: ModelInfo
-	provider?: ApiProvider
 }
 
-export const ThinkingBudget = ({
-	apiConfiguration,
-	setApiConfigurationField,
-	modelInfo,
-	provider,
-}: ThinkingBudgetProps) => {
-	const tokens = apiConfiguration?.modelMaxTokens || modelInfo?.maxTokens || 64_000
+export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, modelInfo }: ThinkingBudgetProps) => {
+	const tokens = apiConfiguration?.modelMaxTokens || 16_384
 	const tokensMin = 8192
 	const tokensMax = modelInfo?.maxTokens || 64_000
 

+ 0 - 2
webview-ui/src/components/settings/__tests__/ApiOptions.test.tsx

@@ -92,7 +92,6 @@ describe("ApiOptions", () => {
 			})
 
 			expect(screen.getByTestId("thinking-budget")).toBeInTheDocument()
-			expect(screen.getByTestId("thinking-budget")).toHaveAttribute("data-provider", "anthropic")
 		})
 
 		it("should show ThinkingBudget for Vertex models that support thinking", () => {
@@ -104,7 +103,6 @@ describe("ApiOptions", () => {
 			})
 
 			expect(screen.getByTestId("thinking-budget")).toBeInTheDocument()
-			expect(screen.getByTestId("thinking-budget")).toHaveAttribute("data-provider", "vertex")
 		})
 
 		it("should not show ThinkingBudget for models that don't support thinking", () => {

+ 3 - 23
webview-ui/src/components/settings/__tests__/ThinkingBudget.test.tsx

@@ -1,7 +1,6 @@
-import React from "react"
 import { render, screen, fireEvent } from "@testing-library/react"
 import { ThinkingBudget } from "../ThinkingBudget"
-import { ApiProvider, ModelInfo } from "../../../../../src/shared/api"
+import { ModelInfo } from "../../../../../src/shared/api"
 
 // Mock Slider component
 jest.mock("@/components/ui", () => ({
@@ -25,11 +24,11 @@ describe("ThinkingBudget", () => {
 		supportsPromptCache: true,
 		supportsImages: true,
 	}
+
 	const defaultProps = {
 		apiConfiguration: {},
 		setApiConfigurationField: jest.fn(),
 		modelInfo: mockModelInfo,
-		provider: "anthropic" as ApiProvider,
 	}
 
 	beforeEach(() => {
@@ -60,25 +59,7 @@ describe("ThinkingBudget", () => {
 		expect(screen.getAllByTestId("slider")).toHaveLength(2)
 	})
 
-	it("should use modelMaxThinkingTokens field for Anthropic provider", () => {
-		const setApiConfigurationField = jest.fn()
-
-		render(
-			<ThinkingBudget
-				{...defaultProps}
-				apiConfiguration={{ modelMaxThinkingTokens: 4096 }}
-				setApiConfigurationField={setApiConfigurationField}
-				provider="anthropic"
-			/>,
-		)
-
-		const sliders = screen.getAllByTestId("slider")
-		fireEvent.change(sliders[1], { target: { value: "5000" } })
-
-		expect(setApiConfigurationField).toHaveBeenCalledWith("modelMaxThinkingTokens", 5000)
-	})
-
-	it("should use modelMaxThinkingTokens field for Vertex provider", () => {
+	it("should update modelMaxThinkingTokens", () => {
 		const setApiConfigurationField = jest.fn()
 
 		render(
@@ -86,7 +67,6 @@ describe("ThinkingBudget", () => {
 				{...defaultProps}
 				apiConfiguration={{ modelMaxThinkingTokens: 4096 }}
 				setApiConfigurationField={setApiConfigurationField}
-				provider="vertex"
 			/>,
 		)