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

Scroll on 'main scrollable element' when possible #405

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions evals/evals.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@
{
"name": "extract_research_reports",
"categories": ["text_extract"]
},
{
"name": "extract_apartments",
"categories": ["text_extract"]
},
{
"name": "extract_zillow",
"categories": ["text_extract"]
}
]
}
70 changes: 70 additions & 0 deletions evals/tasks/extract_apartments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { z } from "zod";
import { initStagehand } from "../initStagehand";
import { EvalFunction } from "../../types/evals";

export const extract_apartments: EvalFunction = async ({
modelName,
logger,
useTextExtract,
}) => {
const { stagehand, initResponse } = await initStagehand({
modelName,
logger,
domSettleTimeoutMs: 3000,
});

const { debugUrl, sessionUrl } = initResponse;

await stagehand.page.goto(
"https://www.apartments.com/san-francisco-ca/2-bedrooms/",
);
const apartment_listings = await stagehand.page.extract({
instruction:
"Extract all the apartment listings with their prices and their addresses.",
schema: z.object({
listings: z.array(
z.object({
price: z.string().describe("The price of the listing"),
trails: z.string().describe("The address of the listing"),
}),
),
}),
modelName,
useTextExtract,
});

await stagehand.close();
const listings = apartment_listings.listings;
const expectedLength = 40;

if (listings.length < expectedLength) {
logger.error({
message: "Incorrect number of listings extracted",
level: 0,
auxiliary: {
expected: {
value: expectedLength.toString(),
type: "integer",
},
actual: {
value: listings.length.toString(),
type: "integer",
},
},
});
return {
_success: false,
error: "Incorrect number of listings extracted",
logs: logger.getLogs(),
debugUrl,
sessionUrl,
};
}

return {
_success: true,
logs: logger.getLogs(),
debugUrl,
sessionUrl,
};
};
70 changes: 70 additions & 0 deletions evals/tasks/extract_zillow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { z } from "zod";
import { initStagehand } from "../initStagehand";
import { EvalFunction } from "../../types/evals";

export const extract_zillow: EvalFunction = async ({
modelName,
logger,
useTextExtract,
}) => {
const { stagehand, initResponse } = await initStagehand({
modelName,
logger,
domSettleTimeoutMs: 3000,
});

const { debugUrl, sessionUrl } = initResponse;

await stagehand.page.goto(
"https://www.zillow.com/homes/San-Francisco,-CA_rb/",
);
const real_estate_listings = await stagehand.page.extract({
instruction:
"Extract all the real estate listings with their prices and their addresses.",
schema: z.object({
listings: z.array(
z.object({
price: z.string().describe("The price of the listing"),
trails: z.string().describe("The address of the listing"),
}),
),
}),
modelName,
useTextExtract,
});

await stagehand.close();
const listings = real_estate_listings.listings;
const expectedLength = 38;
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure this is fixed? this doesn't seem sustainable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can beef this up a tad by making sure fields are filled within the object, but hardcoded expected values on zillow is going to be a nightmare to maintain.


if (listings.length < expectedLength) {
logger.error({
message: "Incorrect number of listings extracted",
level: 0,
auxiliary: {
expected: {
value: expectedLength.toString(),
type: "integer",
},
actual: {
value: listings.length.toString(),
type: "integer",
},
},
});
return {
_success: false,
error: "Incorrect number of listings extracted",
logs: logger.getLogs(),
debugUrl,
sessionUrl,
};
}

return {
_success: true,
logs: logger.getLogs(),
debugUrl,
sessionUrl,
};
};
5 changes: 4 additions & 1 deletion lib/dom/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ declare global {
}>;
debugDom: () => Promise<void>;
cleanupDebug: () => void;
scrollToHeight: (height: number) => Promise<void>;
scrollToHeight: (
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we make this serialized json

containerOrWindow: HTMLElement | Window,
height: number,
) => Promise<void>;
waitForDomSettle: () => Promise<void>;
__playwright?: unknown;
__pw_manual?: unknown;
Expand Down
Loading
Loading