-
Notifications
You must be signed in to change notification settings - Fork 868
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
base: main
Are you sure you want to change the base?
add new models #867
Changes from 1 commit
3d7f0e8
026a598
c79bf73
b71a12e
df1dda4
eb6f48e
b79c792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,19 @@ import { | |
|
||
// Map model names to their provider types | ||
const modelToAgentProviderMap: Record<string, AgentType> = { | ||
// OpenAI models | ||
"computer-use-preview": "openai", | ||
"computer-use-preview-2025-03-11": "openai", | ||
"claude-3-7-sonnet-latest": "anthropic", | ||
// Anthropic models | ||
"claude-sonnet-4-0": "anthropic", | ||
"claude-sonnet-4-20250514": "anthropic", | ||
"claude-opus-4-0": "anthropic", | ||
"claude-opus-4-20250514": "anthropic", | ||
"claude-3-7-sonnet-latest": "anthropic", | ||
"claude-3-7-sonnet-20250219": "anthropic", | ||
"claude-3-5-sonnet-latest": "anthropic", | ||
"claude-3-5-sonnet-20241022": "anthropic", | ||
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. style: Consider sorting model versions chronologically - 20240620 appears after 20241022 |
||
"claude-3-5-sonnet-20240620": "anthropic", | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,6 +42,7 @@ export class AnthropicCUAClient extends AgentClient { | |||||
// Process client options | ||||||
this.apiKey = | ||||||
(clientOptions?.apiKey as string) || process.env.ANTHROPIC_API_KEY || ""; | ||||||
console.log("USING API KEY", this.apiKey); | ||||||
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. logic: Logging API keys is a security risk. Consider removing this line or masking the key
Suggested change
|
||||||
this.baseURL = (clientOptions?.baseURL as string) || undefined; | ||||||
|
||||||
// Get thinking budget if specified | ||||||
|
@@ -58,7 +59,7 @@ export class AnthropicCUAClient extends AgentClient { | |||||
}; | ||||||
|
||||||
if (this.baseURL) { | ||||||
this.clientOptions.baseUrl = this.baseURL; | ||||||
this.clientOptions.baseURL = this.baseURL; | ||||||
} | ||||||
|
||||||
// Initialize the Anthropic client | ||||||
|
@@ -406,21 +407,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 +480,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 4 models and Claude Sonnet 3.7 use computer_20250124 with computer-use-2025-01-24 | ||||||
if ( | ||||||
sameelarif marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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, | ||||||
|
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,13 +43,11 @@ 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; | ||
if (this.baseURL) { | ||
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 |
||
this.clientOptions.baseURL = this.baseURL; | ||
} | ||
|
||
sameelarif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Store client options for reference | ||
|
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: importing ClientOptions from Anthropic SDK when this is a base class that should be implementation-agnostic. Consider moving specific SDK types to the implementing classes.