-
Notifications
You must be signed in to change notification settings - Fork 843
add new models #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sameelarif
wants to merge
7
commits into
main
Choose a base branch
from
sarif/bb-1089-update-supported-cua-models
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−39
Open
add new models #867
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d7f0e8
add new models
sameelarif 026a598
remove api key log
sameelarif c79bf73
Update lib/agent/AnthropicCUAClient.ts
sameelarif b71a12e
Update lib/agent/OpenAICUAClient.ts
sameelarif df1dda4
fix client options type
sameelarif eb6f48e
Merge branch 'sarif/bb-1089-update-supported-cua-models' of https://g…
sameelarif b79c792
changeset
sameelarif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@browserbasehq/stagehand": patch | ||
--- | ||
|
||
Added support for new Anthropic computer-use models. Also added support for passing in new Anthropic models into Stagehand via the legacy (non AI SDK) format until we fully migrate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Anthropic from "@anthropic-ai/sdk"; | ||
import Anthropic, { ClientOptions } from "@anthropic-ai/sdk"; | ||
import { LogLine } from "@/types/log"; | ||
import { | ||
AgentAction, | ||
|
@@ -35,7 +35,7 @@ export class AnthropicCUAClient extends AgentClient { | |
type: AgentType, | ||
modelName: string, | ||
userProvidedInstructions?: string, | ||
clientOptions?: Record<string, unknown>, | ||
clientOptions?: ClientOptions, | ||
) { | ||
super(type, modelName, userProvidedInstructions); | ||
|
||
|
@@ -44,21 +44,13 @@ export class AnthropicCUAClient extends AgentClient { | |
(clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || ""; | ||
this.baseURL = (clientOptions?.baseURL as string) || undefined; | ||
|
||
// Get thinking budget if specified | ||
if ( | ||
clientOptions?.thinkingBudget && | ||
typeof clientOptions.thinkingBudget === "number" | ||
) { | ||
this.thinkingBudget = clientOptions.thinkingBudget; | ||
} | ||
|
||
Comment on lines
-47
to
-54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed since the key did not exist on the client options type |
||
// Store client options for reference | ||
this.clientOptions = { | ||
apiKey: this.apiKey, | ||
}; | ||
|
||
if (this.baseURL) { | ||
this.clientOptions.baseUrl = this.baseURL; | ||
this.clientOptions.baseURL = this.baseURL; | ||
} | ||
|
||
// Initialize the Anthropic client | ||
|
@@ -406,21 +398,26 @@ export class AnthropicCUAClient extends AgentClient { | |
? { type: "enabled" as const, budget_tokens: this.thinkingBudget } | ||
: undefined; | ||
|
||
// Determine the appropriate computer type and beta flag based on model | ||
const { computerType, betaFlag } = this.getComputerUseConfigForModel( | ||
this.modelName, | ||
); | ||
|
||
// Create the request parameters | ||
const requestParams: Record<string, unknown> = { | ||
model: this.modelName, | ||
max_tokens: 4096, | ||
messages: messages, | ||
tools: [ | ||
{ | ||
type: "computer_20250124", // Use the latest version for Claude 3.7 Sonnet | ||
type: computerType, | ||
name: "computer", | ||
display_width_px: this.currentViewport.width, | ||
display_height_px: this.currentViewport.height, | ||
display_number: 1, | ||
}, | ||
], | ||
betas: ["computer-use-2025-01-24"], | ||
betas: [betaFlag], | ||
}; | ||
|
||
// Add system parameter if provided | ||
|
@@ -474,6 +471,43 @@ export class AnthropicCUAClient extends AgentClient { | |
} | ||
} | ||
|
||
/** | ||
* Get the appropriate computer type and beta flag for a given model | ||
*/ | ||
private getComputerUseConfigForModel(modelName: string): { | ||
computerType: string; | ||
betaFlag: string; | ||
} { | ||
// Claude 3.5 models use computer_20241022 with computer-use-2024-10-22 | ||
if ( | ||
modelName.includes("claude-3-5-sonnet") || | ||
modelName.includes("claude-3-5") | ||
) { | ||
return { | ||
computerType: "computer_20241022", | ||
betaFlag: "computer-use-2024-10-22", | ||
}; | ||
} | ||
|
||
// Claude 4 models and Claude Sonnet 3.7 use computer_20250124 with computer-use-2025-01-24 | ||
if ( | ||
modelName.includes("claude-4") || | ||
modelName.includes("claude-3-7") || | ||
modelName.includes("claude-3-7-sonnet") | ||
) { | ||
return { | ||
computerType: "computer_20250124", | ||
betaFlag: "computer-use-2025-01-24", | ||
}; | ||
} | ||
|
||
// Default fallback for other models | ||
return { | ||
computerType: "computer_20250124", | ||
betaFlag: "computer-use-2025-01-24", | ||
}; | ||
} | ||
|
||
async takeAction( | ||
toolUseItems: ToolUseItem[], | ||
logger: (message: LogLine) => void, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import OpenAI from "openai"; | ||
import { LogLine } from "../../types/log"; | ||
import { | ||
AgentAction, | ||
AgentExecutionOptions, | ||
AgentResult, | ||
AgentType, | ||
AgentExecutionOptions, | ||
ResponseInputItem, | ||
ResponseItem, | ||
ComputerCallItem, | ||
FunctionCallItem, | ||
ResponseInputItem, | ||
ResponseItem, | ||
} from "@/types/agent"; | ||
import { AgentClient } from "./AgentClient"; | ||
import { AgentScreenshotProviderError } from "@/types/stagehandErrors"; | ||
import OpenAI, { ClientOptions } from "openai"; | ||
import { LogLine } from "../../types/log"; | ||
import { AgentClient } from "./AgentClient"; | ||
|
||
/** | ||
* Client for OpenAI's Computer Use Assistant API | ||
|
@@ -34,7 +34,7 @@ export class OpenAICUAClient extends AgentClient { | |
type: AgentType, | ||
modelName: string, | ||
userProvidedInstructions?: string, | ||
clientOptions?: Record<string, unknown>, | ||
clientOptions?: ClientOptions, | ||
) { | ||
super(type, modelName, userProvidedInstructions); | ||
|
||
|
@@ -43,15 +43,21 @@ export class OpenAICUAClient extends AgentClient { | |
(clientOptions?.apiKey as string) || process.env.OPENAI_API_KEY || ""; | ||
this.organization = | ||
(clientOptions?.organization as string) || process.env.OPENAI_ORG; | ||
this.baseURL = (clientOptions?.baseURL as string) || undefined; | ||
|
||
// Get environment if specified | ||
if ( | ||
clientOptions?.environment && | ||
typeof clientOptions.environment === "string" | ||
) { | ||
this.environment = clientOptions.environment; | ||
Comment on lines
-48
to
-52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed since the environment key did not exist on the client options type |
||
// Store client options for reference | ||
this.clientOptions = { | ||
apiKey: this.apiKey, | ||
}; | ||
|
||
if (this.baseURL) { | ||
this.clientOptions.baseURL = this.baseURL; | ||
} | ||
sameelarif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Initialize the OpenAI client | ||
this.client = new OpenAI(this.clientOptions); | ||
|
||
// Store client options for reference | ||
this.clientOptions = { | ||
apiKey: this.apiKey, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider sorting model versions chronologically - 20240620 appears after 20241022