-
Notifications
You must be signed in to change notification settings - Fork 671
Extract links #655
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
Merged
Merged
Extract links #655
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5ddb2e8
remove redundant static text children
seanmcguire12 d31329e
prettier
seanmcguire12 346acd8
changeset
seanmcguire12 716f6a4
add link mapping to TreeResult
seanmcguire12 16d6d25
changeset
seanmcguire12 4f54003
Merge remote-tracking branch 'origin/main' into collapse-duplicate-te…
seanmcguire12 2e1a8cc
Merge branch 'collapse-duplicate-text-nodes' into add-link-mapping
seanmcguire12 0866877
get url field from metadata inference call
seanmcguire12 e33f23c
map id->url
seanmcguire12 4be76c3
update prompt
seanmcguire12 fc82c01
useTextExtract should be default false
seanmcguire12 81a5233
changeset
seanmcguire12 a321a9d
Merge branch 'add-link-mapping' into extract-links
seanmcguire12 908a8bc
Merge remote-tracking branch 'origin/main' into extract-links
seanmcguire12 8c99828
better naming
seanmcguire12 3f57082
Merge remote-tracking branch 'origin/main' into extract-links
seanmcguire12 d794ad3
rm changeset
seanmcguire12 49b992f
schema patch approach
seanmcguire12 e511502
rm urlField from metadata schema
seanmcguire12 42ba19d
empty string if no URL found for ID
seanmcguire12 87c7ddb
add eval
seanmcguire12 a6a1184
add another eval
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 hidden or 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,5 @@ | ||
--- | ||
"@browserbasehq/stagehand": minor | ||
--- | ||
|
||
extract links |
This file contains hidden or 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 hidden or 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,125 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
import { z } from "zod"; | ||
|
||
export const extract_jfk_links: EvalFunction = async ({ | ||
logger, | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
}) => { | ||
try { | ||
await stagehand.page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/jfk/", | ||
); | ||
|
||
const extraction = await stagehand.page.extract({ | ||
instruction: | ||
"extract all the record file name and their corresponding links", | ||
schema: z.object({ | ||
records: z.array( | ||
z.object({ | ||
file_name: z.string().describe("the file name of the record"), | ||
link: z.string().url(), | ||
}), | ||
), | ||
}), | ||
}); | ||
|
||
// The list of records we expect to see | ||
const expectedRecords = [ | ||
{ | ||
file_name: "104-10003-10041.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10003-10041.pdf", | ||
}, | ||
{ | ||
file_name: "104-10004-10143 (C06932208).pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10004-10143%20(C06932208).pdf", | ||
}, | ||
{ | ||
file_name: "104-10004-10143.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10004-10143.pdf", | ||
}, | ||
{ | ||
file_name: "104-10004-10156.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10004-10156.pdf", | ||
}, | ||
{ | ||
file_name: "104-10004-10213.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10004-10213.pdf", | ||
}, | ||
{ | ||
file_name: "104-10005-10321.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10005-10321.pdf", | ||
}, | ||
{ | ||
file_name: "104-10006-10247.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10006-10247.pdf", | ||
}, | ||
{ | ||
file_name: "104-10007-10345.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10007-10345.pdf", | ||
}, | ||
{ | ||
file_name: "104-10009-10021.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10009-10021.pdf", | ||
}, | ||
{ | ||
file_name: "104-10009-10222.pdf", | ||
link: "https://www.archives.gov/files/research/jfk/releases/2025/0318/104-10009-10222.pdf", | ||
}, | ||
]; | ||
|
||
const extractedRecords = extraction.records; | ||
|
||
// Check that all expected records exist in the extraction | ||
const missingRecords = expectedRecords.filter((expected) => { | ||
return !extractedRecords.some( | ||
(r) => r.file_name === expected.file_name && r.link === expected.link, | ||
); | ||
}); | ||
|
||
// Check that the extraction array is exactly length 10 | ||
if (extractedRecords.length !== 10) { | ||
await stagehand.close(); | ||
return { | ||
_success: false, | ||
reason: `Extraction has ${extractedRecords.length} records (expected 10).`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
|
||
if (missingRecords.length > 0) { | ||
await stagehand.close(); | ||
return { | ||
_success: false, | ||
reason: "Missing one or more expected records.", | ||
missingRecords, | ||
extractedRecords, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
|
||
// If we reach here, the number of records is correct, and all are present | ||
await stagehand.close(); | ||
return { | ||
_success: true, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
await stagehand.close(); | ||
|
||
return { | ||
_success: false, | ||
error: JSON.parse(JSON.stringify(error, null, 2)), | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
}; |
This file contains hidden or 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,52 @@ | ||
import { EvalFunction } from "@/types/evals"; | ||
import { z } from "zod"; | ||
|
||
export const extract_single_link: EvalFunction = async ({ | ||
logger, | ||
debugUrl, | ||
sessionUrl, | ||
stagehand, | ||
}) => { | ||
try { | ||
await stagehand.page.goto( | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/geniusee/", | ||
); | ||
|
||
const extraction = await stagehand.page.extract({ | ||
instruction: "extract the link to the 'contact us' page", | ||
schema: z.object({ | ||
link: z.string().url(), | ||
}), | ||
}); | ||
|
||
await stagehand.close(); | ||
const extractedLink = extraction.link; | ||
const expectedLink = | ||
"https://browserbase.github.io/stagehand-eval-sites/sites/geniusee/#contact"; | ||
|
||
if (extractedLink === expectedLink) { | ||
return { | ||
_success: true, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
return { | ||
_success: false, | ||
reason: `Extracted link: ${extractedLink} does not match expected link: ${expectedLink}`, | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} catch (error) { | ||
await stagehand.close(); | ||
return { | ||
_success: false, | ||
error: JSON.parse(JSON.stringify(error, null, 2)), | ||
debugUrl, | ||
sessionUrl, | ||
logs: logger.getLogs(), | ||
}; | ||
} | ||
}; |
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.
Uh oh!
There was an error while loading. Please reload this page.