-
Notifications
You must be signed in to change notification settings - Fork 209
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
seanmcguire12
wants to merge
15
commits into
main
Choose a base branch
from
find_scollable_elems
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.
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e8316a5
use main scrollable container in processAllOfDom
seanmcguire12 c02b37b
update actHandler with new function signature
seanmcguire12 3f84f44
update function definition in global.d.ts with new function signature
seanmcguire12 39b8dd5
new evals
seanmcguire12 cdc58b6
Merge remote-tracking branch 'origin/main' into find_scollable_elems
seanmcguire12 3be2787
add StagehandContainer
seanmcguire12 34866cd
handle case where mainScrollableElem == root element
seanmcguire12 43f7296
rm waitForScrollEnd from StagehandContainer
seanmcguire12 c02fb69
prettier
seanmcguire12 2762305
call scrollTo inside browser
seanmcguire12 9af9984
Merge remote-tracking branch 'origin/main' into find_scollable_elems
seanmcguire12 a07fdba
use cloned site for zillow
seanmcguire12 26aa1d4
timeout between scrolls
seanmcguire12 a57989d
prettier
seanmcguire12 0e75e6c
changeset
seanmcguire12 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 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 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,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, | ||
}; | ||
}; |
This file contains 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,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; | ||
|
||
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, | ||
}; | ||
}; |
This file contains 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 |
---|---|---|
|
@@ -19,7 +19,10 @@ declare global { | |
}>; | ||
debugDom: () => Promise<void>; | ||
cleanupDebug: () => void; | ||
scrollToHeight: (height: number) => Promise<void>; | ||
scrollToHeight: ( | ||
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. nit: can we make this serialized json |
||
containerOrWindow: HTMLElement | Window, | ||
height: number, | ||
) => Promise<void>; | ||
waitForDomSettle: () => Promise<void>; | ||
__playwright?: unknown; | ||
__pw_manual?: unknown; | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
are we sure this is fixed? this doesn't seem sustainable
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.
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.