-
Notifications
You must be signed in to change notification settings - Fork 2.6k
added Browserbase loader #5248
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
added Browserbase loader #5248
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f56f1af
added browserbase integration
mishushakov 13796c0
Added docs to Browserbase loader
mishushakov a178d6b
ran the build command
mishushakov 00dfe91
updated browserbase integration for review
mishushakov db1bbfc
nits
bracesproul a240cb5
Merge branch 'main' into browserbase
bracesproul 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
34 changes: 34 additions & 0 deletions
34
docs/core_docs/docs/integrations/document_loaders/web_loaders/browserbase.mdx
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,34 @@ | ||
# Browserbase Loader | ||
|
||
## Description | ||
|
||
[Browserbase](https://browserbase.com) is a serverless platform for running headless browsers, it offers advanced debugging, session recordings, stealth mode, integrated proxies and captcha solving. | ||
|
||
## Installation | ||
|
||
- Get an API key from [browserbase.com](https://browserbase.com) and set it in environment variables (`BROWSERBASE_API_KEY`). | ||
- Install the [Browserbase SDK](http://github.com/browserbase/js-sdk): | ||
|
||
``` | ||
npm i @browserbasehq/sdk | ||
``` | ||
|
||
## Example | ||
|
||
Utilize the BrowserbaseLoader as follows to allow your agent to load websites: | ||
|
||
```js | ||
import { BrowserbaseLoader } from "langchain/document_loaders/web/browserbase.js"; | ||
|
||
const loader = new BrowserbaseLoader(["https://example.com"], { textContent: true }); | ||
const docs = await loader.load(); | ||
``` | ||
|
||
## Arguments | ||
|
||
- `urls`: Required. List of URLs to load. | ||
|
||
## Options | ||
|
||
- `api_key`: Optional. Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable. | ||
- `text_content`: Optional. Load pages as readable text. Default is `False`. |
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
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 |
---|---|---|
|
@@ -546,6 +546,10 @@ | |
"document_loaders/web/azure_blob_storage_file.js", | ||
"document_loaders/web/azure_blob_storage_file.d.ts", | ||
"document_loaders/web/azure_blob_storage_file.d.cts", | ||
"document_loaders/web/browserbase.cjs", | ||
"document_loaders/web/browserbase.js", | ||
"document_loaders/web/browserbase.d.ts", | ||
"document_loaders/web/browserbase.d.cts", | ||
"document_loaders/web/cheerio.cjs", | ||
"document_loaders/web/cheerio.js", | ||
"document_loaders/web/cheerio.d.ts", | ||
|
@@ -1222,6 +1226,7 @@ | |
"@aws-sdk/credential-provider-node": "^3.388.0", | ||
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. Hey there! I noticed that the addition of "@browserbasehq/sdk" in the package.json file introduces a new dependency to the project. This change is flagged for maintainers to review the impact on peer/dev/hard dependencies. Keep up the great work! |
||
"@aws-sdk/types": "^3.357.0", | ||
"@azure/storage-blob": "^12.15.0", | ||
"@browserbasehq/sdk": "^1.0.0", | ||
"@cloudflare/workers-types": "^4.20230922.0", | ||
"@faker-js/faker": "^7.6.0", | ||
"@gomomento/sdk": "^1.51.1", | ||
|
@@ -1309,6 +1314,7 @@ | |
"@aws-sdk/client-sfn": "^3.310.0", | ||
"@aws-sdk/credential-provider-node": "^3.388.0", | ||
"@azure/storage-blob": "^12.15.0", | ||
"@browserbasehq/sdk": "*", | ||
"@gomomento/sdk": "^1.51.1", | ||
"@gomomento/sdk-core": "^1.51.1", | ||
"@gomomento/sdk-web": "^1.51.1", | ||
|
@@ -1371,6 +1377,9 @@ | |
"@azure/storage-blob": { | ||
"optional": true | ||
}, | ||
"@browserbasehq/sdk": { | ||
"optional": true | ||
}, | ||
"@gomomento/sdk": { | ||
"optional": true | ||
}, | ||
|
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,83 @@ | ||
import { Document } from "@langchain/core/documents"; | ||
import type { BrowserbaseLoadOptions } from "@browserbasehq/sdk"; | ||
import { BaseDocumentLoader } from "../base.js"; | ||
import type { DocumentLoader } from "../base.js"; | ||
|
||
type BrowserbaseLoaderOptions = BrowserbaseLoadOptions & { | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
apiKey?: string; | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
/** | ||
* Load pre-rendered web pages using a headless browser hosted on Browserbase. | ||
* | ||
* Depends on `@browserbasehq/sdk` package. | ||
* Get your API key from https://browserbase.com | ||
* | ||
* @param {string[]} urls - The URLs of the web pages to load. | ||
* @param {BrowserbaseLoaderOptions} [options] - Browserbase client options. | ||
*/ | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export class BrowserbaseLoader | ||
extends BaseDocumentLoader | ||
implements DocumentLoader | ||
{ | ||
urls: string[]; | ||
|
||
options: BrowserbaseLoaderOptions; | ||
|
||
constructor(urls: string[], options: BrowserbaseLoaderOptions = {}) { | ||
super(); | ||
this.urls = urls; | ||
this.options = options; | ||
} | ||
|
||
/** | ||
* Load pages from URLs. | ||
* | ||
* @returns {Promise<Document[]>} - A generator that yields loaded documents. | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
async load(): Promise<Document[]> { | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const documents: Document[] = []; | ||
for await (const doc of this.lazyLoad()) { | ||
documents.push(doc); | ||
} | ||
|
||
return documents; | ||
} | ||
|
||
/** | ||
* Load pages from URLs. | ||
* | ||
* @returns {Generator<Document>} - A generator that yields loaded documents. | ||
*/ | ||
async *lazyLoad() { | ||
const browserbase = await BrowserbaseLoader.imports(this.options.apiKey); | ||
const pages = await browserbase.loadURLs(this.urls, this.options); | ||
|
||
let index = 0; | ||
for await (const page of pages) { | ||
yield new Document({ | ||
pageContent: page, | ||
metadata: { | ||
url: this.urls[index], | ||
}, | ||
}); | ||
|
||
index += index + 1; | ||
} | ||
} | ||
|
||
static async imports(apiKey?: string) { | ||
try { | ||
const { default: Browserbase } = await import("@browserbasehq/sdk"); | ||
return new Browserbase(apiKey); | ||
} catch (error) { | ||
throw new Error( | ||
"You must run " + | ||
"`npm install --save @browserbasehq/sdk` " + | ||
"to use the Browserbase loader." | ||
); | ||
} | ||
} | ||
} | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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.