-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(community): Add a Hyperbrowser package for the js library #7960
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
Open
AHarmlessPyro
wants to merge
8
commits into
langchain-ai:main
Choose a base branch
from
hyperbrowserai:main
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ef59f9
Add Hyperbrowser loader and tools
AHarmlessPyro 9b3d41e
Add docs
AHarmlessPyro da9d080
Add related links
AHarmlessPyro 388deb0
Add exports
AHarmlessPyro 5307e4b
Fix API Key naming
AHarmlessPyro 3f935fe
Add extra session options for document loader
AHarmlessPyro 574ca84
Match template for doc loader
AHarmlessPyro f6fb84e
Update docs to follow template
AHarmlessPyro 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
196 changes: 196 additions & 0 deletions
196
docs/core_docs/docs/integrations/document_loaders/web_loaders/hyperbrowser.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,196 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
# Hyperbrowser | ||
|
||
## Overview | ||
|
||
The Hyperbrowser document loader provides a way to load web content into your LangChain application using Hyperbrowser's cloud browser infrastructure. It supports: | ||
|
||
- Single-page scraping | ||
- Multi-page crawling | ||
- Multiple output formats (markdown, HTML, links) | ||
- Advanced browser automation features | ||
|
||
| Class | Package | Local | [PY support](https://python.langchain.com/docs/integrations/document_loaders/hyperbrowser/)| | ||
| :---: | :---: | :---: | :---: | | ||
| HyperbrowserLoader | langchain-js | ❌ | ✅ | | ||
|
||
## Setup | ||
|
||
To access the Hyperbrowser Document Loader, you'll first need to install the @langchain/community package. You will also need a hyperbrowser account, and the associated API key. | ||
|
||
### Credentials | ||
|
||
You'll need a Hyperbrowser API key. Get one from [Hyperbrowser](https://hyperbrowser.ai/) and set it as an environment variable: | ||
|
||
### Installation | ||
|
||
First, install the required packages: | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community @langchain/core @hyperbrowser/sdk | ||
``` | ||
|
||
|
||
```bash | ||
export HYPERBROWSER_API_KEY="your-api-key" | ||
``` | ||
|
||
Or pass it directly to the loader: | ||
|
||
```typescript | ||
const loader = new HyperbrowserLoader({ | ||
apiKey: "your-api-key", | ||
// ... other options | ||
}); | ||
``` | ||
|
||
## Instantiation | ||
|
||
Load content from a single webpage: | ||
|
||
```typescript | ||
import { HyperbrowserLoader } from "@langchain/community/document_loaders/web/hyperbrowser"; | ||
|
||
const loader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["markdown"] | ||
}); | ||
|
||
const docs = await loader.load(); | ||
``` | ||
|
||
## Advanced Usage | ||
|
||
### Multi-page Loading | ||
|
||
Load content from multiple linked pages: | ||
|
||
```typescript | ||
import { HyperbrowserLoader } from "@langchain/community/document_loaders/web/hyperbrowser"; | ||
|
||
const loader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "crawl", | ||
maxPages: 10, | ||
outputFormat: ["markdown"] | ||
}); | ||
|
||
const docs = await loader.load(); | ||
``` | ||
|
||
### Different Output Formats | ||
|
||
```typescript | ||
// Markdown output | ||
const markdownLoader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["markdown"] | ||
}); | ||
|
||
// HTML output | ||
const htmlLoader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["html"] | ||
}); | ||
|
||
// Multiple formats | ||
const multiFormatLoader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["markdown", "html", "links"] | ||
}); | ||
``` | ||
|
||
### With Session Options | ||
|
||
```typescript | ||
const loader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["markdown"], | ||
sessionOptions: { | ||
useProxy: true, | ||
solveCaptchas: true, | ||
... | ||
} | ||
}); | ||
``` | ||
|
||
## Parameters | ||
|
||
### Required Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --------- | ---- | ----------- | | ||
| `url` | `string` | The URL to scrape or crawl | | ||
| `mode` | `"scrape" \| "crawl"` | Whether to scrape a single page or crawl multiple pages | | ||
|
||
### Optional Parameters | ||
|
||
| Parameter | Type | Default | Description | | ||
| --------- | ---- | ------- | ----------- | | ||
| `outputFormat` | `Array<"markdown" \| "html" \| "links" \| "screenshot">` | `["markdown"]` | Desired output formats | | ||
| `maxPages` | `number` | `10` | Maximum pages to crawl (crawl mode only) | | ||
| `sessionOptions` | `object` | See below | A complete list of options can be found on our [docs](https://docs.hyperbrowser.ai/reference/api-reference/sessions#api-session)| | ||
|
||
## Document Schema | ||
|
||
Each document in the returned array has this structure: | ||
|
||
```typescript | ||
interface Document { | ||
pageContent: string; // The extracted content in specified format | ||
metadata: { | ||
source: string; // The URL of the page | ||
timestamp?: string; // When the page was scraped | ||
title?: string; // Page title if available | ||
// ... other metadata from the page | ||
}; | ||
} | ||
``` | ||
|
||
Example document: | ||
|
||
```typescript | ||
{ | ||
pageContent: "# Main Title\n\nArticle content here...", | ||
metadata: { | ||
source: "https://example.com/article", | ||
timestamp: "2024-03-20T10:30:00Z", | ||
title: "Example Article" | ||
} | ||
} | ||
``` | ||
|
||
## Metadata Handling | ||
|
||
The loader automatically extracts and includes metadata: | ||
|
||
```typescript | ||
const loader = new HyperbrowserLoader({ | ||
url: "https://example.com", | ||
mode: "scrape", | ||
outputFormat: ["markdown"] | ||
}); | ||
|
||
const docs = await loader.load(); | ||
console.log(docs[0].metadata); | ||
// { | ||
// source: "https://example.com", | ||
// timestamp: "2024-03-20T10:30:00Z", | ||
// title: "Example Page Title" | ||
// } | ||
``` | ||
|
||
## Related | ||
|
||
- Tool [conceptual guide](docs/concepts/document_loaders) | ||
- Tool [how-to guides](/docs/how_to/#document-loaders) | ||
- [Hyperbrowser Docs](https://docs.hyperbrowser.ai) | ||
- [Hyperbrowser Browser Agents and Automation Tools](/docs/integrations/tools/hyperbrowser) |
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.
Package
should be@langchain/community
- apologies but I don't think I have access to push to your branch to make changes myself.