Skip to content
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

add o1 to model #372

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-hats-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

add o1 model support
3 changes: 2 additions & 1 deletion lib/cache/BaseCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ export class BaseCache<T extends CacheEntry> {
process.on("SIGINT", releaseLockAndExit);
process.on("SIGTERM", releaseLockAndExit);
process.on("uncaughtException", (err) => {
console.log("uncaught exception", err);
this.logger({
category: "base_cache",
message: "uncaught exception",
level: 2,
auxiliary: {
error: {
value: err.message,
value: JSON.stringify(err),
type: "string",
},
trace: {
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/actHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class StagehandActHandler {
if (
llmClient.modelName === "o1-mini" ||
llmClient.modelName === "o1-preview" ||
llmClient.modelName.startsWith("o1-")
llmClient.modelName === "o1"
) {
verifyLLmClient = this.llmProvider.getClient(
"gpt-4o",
Expand Down
1 change: 1 addition & 0 deletions lib/llm/LLMProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class LLMProvider {
"gpt-4o-2024-08-06": "openai",
"o1-mini": "openai",
"o1-preview": "openai",
o1: "openai",
"claude-3-5-sonnet-latest": "anthropic",
"claude-3-5-sonnet-20240620": "anthropic",
"claude-3-5-sonnet-20241022": "anthropic",
Expand Down
44 changes: 43 additions & 1 deletion lib/llm/OpenAIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ export class OpenAIClient extends LLMClient {
});
}
}

if (this.modelName === "o1") {
delete options.temperature;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead do something like:

{ temperature, top_p, frequency_penalty, presence_penalty, ...options } = options

then we can log each as being removed since model is o1

delete options.top_p;
delete options.frequency_penalty;
delete options.presence_penalty;
}

if (
options.temperature &&
(this.modelName === "o1-mini" || this.modelName === "o1-preview")
(this.modelName === "o1-mini" ||
this.modelName === "o1-preview" ||
this.modelName === "o1")
) {
throw new Error("Temperature is not supported for o1 models");
}
Expand Down Expand Up @@ -411,6 +421,22 @@ export class OpenAIClient extends LLMClient {
);
}

this.logger({
category: "openai",
message: "parsed response",
level: 1,
auxiliary: {
parsedData: {
value: JSON.stringify(parsedData),
type: "object",
},
requestId: {
value: requestId,
type: "string",
},
},
});

return parsedData;
}

Expand All @@ -437,6 +463,22 @@ export class OpenAIClient extends LLMClient {
this.cache.set(cacheOptions, response, options.requestId);
}

this.logger({
category: "openai",
message: "final response",
level: 1,
auxiliary: {
response: {
value: JSON.stringify(response),
type: "object",
},
requestId: {
value: requestId,
type: "string",
},
},
});

// if the function was called with a response model, it would have returned earlier
// so we can safely cast here to T, which defaults to ChatCompletion
return response as T;
Expand Down
1 change: 1 addition & 0 deletions types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const AvailableModelSchema = z.enum([
"claude-3-5-sonnet-20240620",
"o1-mini",
"o1-preview",
"o1",
]);

export type AvailableModel = z.infer<typeof AvailableModelSchema>;
Expand Down
Loading