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

[WIP - do not merge] Fm/actions not found #78

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions evals/index.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const costar = async () => {
}
};


const google_jobs = async () => {
const stagehand = new Stagehand({ env: "LOCAL", verbose: 2, debugDom: true, headless: process.env.HEADLESS !== 'false' });
await stagehand.init({ modelName: "gpt-4o-2024-08-06" });
Expand All @@ -173,8 +174,8 @@ const google_jobs = async () => {
await stagehand.act({ action: "input new york city into location" });

await stagehand.act({ action: "click on the search button" });

await stagehand.act({ action: "click on the learn more button for the first job" });
// NOTE: "click on the first Learn More button" is not working - the span for learn more is not clickable and the a href is after it
await stagehand.act({ action: "click on the first job link" });

const jobDetails = await stagehand.extract({
instruction: "Extract the following details from the job posting: application deadline, minimum qualifications (degree and years of experience), and preferred qualifications (degree and years of experience)",
Expand All @@ -198,11 +199,9 @@ const google_jobs = async () => {
Object.values(jobDetails).every(value =>
value !== null &&
value !== undefined &&
value !== '' &&
(typeof value !== 'object' || Object.values(value).every(v =>
v !== null &&
v !== undefined &&
v !== '' &&
(typeof v === 'number' || typeof v === 'string')
))
);
Expand Down
63 changes: 59 additions & 4 deletions evals/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { z } from "zod";
const costar = async () => {
const stagehand = new Stagehand({ env: "LOCAL", verbose: 2, debugDom: true, headless: process.env.HEADLESS !== 'false' });
await stagehand.init();
// TODO: fix this eval
// TODO: fix this eval - it works only on some days depending on the article
try {
await Promise.race([
stagehand.page.goto("https://www.costar.com/"),
Expand Down Expand Up @@ -43,12 +43,67 @@ const costar = async () => {
}
};

const google_jobs = async () => {
const stagehand = new Stagehand({ env: "LOCAL", verbose: 2, debugDom: true, headless: process.env.HEADLESS !== 'false' });
await stagehand.init({ modelName: "gpt-4o-2024-08-06" });

await stagehand.page.goto("https://www.google.com/");
await stagehand.waitForSettledDom();

await stagehand.act({ action: "click on the about page" });

await stagehand.act({ action: "click on the careers page" });

await stagehand.act({ action: "input data scientist into role" });

await stagehand.act({ action: "input new york city into location" });

await stagehand.act({ action: "click on the search button" });
// NOTE: "click on the first Learn More button" is not working - the span for learn more is not clickable and the a href is after it
await stagehand.act({ action: "click on the first job link" });

const jobDetails = await stagehand.extract({
instruction: "Extract the following details from the job posting: application deadline, minimum qualifications (degree and years of experience), and preferred qualifications (degree and years of experience)",
schema: z.object({
applicationDeadline: z.string().describe("The date until which the application window will be open"),
minimumQualifications: z.object({
degree: z.string().describe("The minimum required degree"),
yearsOfExperience: z.number().describe("The minimum required years of experience")
}),
preferredQualifications: z.object({
degree: z.string().describe("The preferred degree"),
yearsOfExperience: z.number().describe("The preferred years of experience")
})
}),
modelName: "gpt-4o-2024-08-06"
});

console.log("Job Details:", jobDetails);

const isJobDetailsValid = jobDetails &&
Object.values(jobDetails).every(value =>
value !== null &&
value !== undefined &&
(typeof value !== 'object' || Object.values(value).every(v =>
v !== null &&
v !== undefined &&
(typeof v === 'number' || typeof v === 'string')
))
);

await stagehand.context.close();

console.log("Job Details valid:", isJobDetailsValid);

return isJobDetailsValid;
};

async function main() {
const [costarResult] = await Promise.all([
costar(),
const [googleJobsResult] = await Promise.all([
google_jobs(),
]);

console.log("Costar result:", costarResult);
console.log("Google jobs result:", googleJobsResult);
}

main().catch(console.error);
25 changes: 20 additions & 5 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ async function example() {
debugDom: true,
});

await stagehand.init({ modelName: "claude-3-5-sonnet-20240620" }); // optionally specify model_name, defaults to "gpt-4o" (as of sept 18, 2024, we need to specify the model name with date, changing on 10/2/2024)
await stagehand.init({ modelName: "claude-3-5-sonnet-20240620" });
await stagehand.page.goto("https://www.nytimes.com/games/wordle/index.html");
await stagehand.act({ action: "start the game" });
await stagehand.act({ action: "close tutorial popup" });

const startGameResult = await stagehand.act({ action: "start the game" });
if (!startGameResult.success) {
console.error("Failed to start the game:", startGameResult.error);
return;
}

const closeTutorialResult = await stagehand.act({ action: "close tutorial popup" });
if (!closeTutorialResult.success) {
console.error("Failed to close tutorial:", closeTutorialResult.error);
// Decide whether to continue or return based on the importance of this action
}

let guesses: { guess: string | null; description: string | null }[] = [];
for (let i = 0; i < 6; i++) {
Expand All @@ -22,8 +32,13 @@ async function example() {
throw new Error("no response when asking for a guess");
}

await stagehand.page.locator("body").pressSequentially(response);
await stagehand.page.keyboard.press("Enter");
try {
await stagehand.page.locator("body").pressSequentially(response);
await stagehand.page.keyboard.press("Enter");
} catch (error) {
console.error("Failed to input guess:", error.message);
continue;
}

const guess = await stagehand.extract({
instruction: "extract the five letter guess at the bottom",
Expand Down
Loading
Loading