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

feat: Add Custom Api Url Param for Self-hosted FireCrawl endpoint #3480

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 7 additions & 1 deletion packages/components/credentials/FireCrawlApi.credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ class FireCrawlApiCredential implements INodeCredential {
constructor() {
this.label = 'FireCrawl API'
this.name = 'fireCrawlApi'
this.version = 1.0
this.version = 2.0
this.description =
'You can find the FireCrawl API token on your <a target="_blank" href="https://www.firecrawl.dev/">FireCrawl account</a> page.'
this.inputs = [
{
label: 'FireCrawl API',
name: 'firecrawlApiToken',
type: 'password'
},
HenryHengZJ marked this conversation as resolved.
Show resolved Hide resolved
{
label: 'FireCrawl API URL',
name: 'firecrawlApiUrl',
type: 'string',
default: 'https://api.firecrawl.dev'
}
]
}
Expand Down
10 changes: 7 additions & 3 deletions packages/components/nodes/documentloaders/FireCrawl/FireCrawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,21 @@ class FirecrawlApp {
interface FirecrawlLoaderParameters {
url: string
apiKey?: string
apiUrl?: string
mode?: 'crawl' | 'scrape'
params?: Record<string, unknown>
}

class FireCrawlLoader extends BaseDocumentLoader {
private apiKey: string
private apiUrl: string
private url: string
private mode: 'crawl' | 'scrape'
private params?: Record<string, unknown>

constructor(loaderParams: FirecrawlLoaderParameters) {
super()
const { apiKey, url, mode = 'crawl', params } = loaderParams
const { apiKey, apiUrl, url, mode = 'crawl', params } = loaderParams
if (!apiKey) {
throw new Error('Firecrawl API key not set. You can set it as FIRECRAWL_API_KEY in your .env file, or pass it to Firecrawl.')
}
Expand All @@ -215,10 +217,11 @@ class FireCrawlLoader extends BaseDocumentLoader {
this.url = url
this.mode = mode
this.params = params
this.apiUrl = apiUrl || 'https://api.firecrawl.dev'
}

public async load(): Promise<DocumentInterface[]> {
const app = new FirecrawlApp({ apiKey: this.apiKey })
const app = new FirecrawlApp({ apiKey: this.apiKey, apiUrl: this.apiUrl })
let firecrawlDocs: FirecrawlDocument[]

if (this.mode === 'scrape') {
Expand Down Expand Up @@ -319,6 +322,7 @@ class FireCrawl_DocumentLoaders implements INode {
const onlyMainContent = nodeData.inputs?.onlyMainContent as boolean
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const firecrawlApiToken = getCredentialParam('firecrawlApiToken', credentialData, nodeData)
const firecrawlApiUrl = getCredentialParam('firecrawlApiUrl', credentialData, nodeData, 'https://api.firecrawl.dev')

const urlPatternsExcludes = nodeData.inputs?.urlPatternsExcludes
? (nodeData.inputs.urlPatternsExcludes.split(',') as string[])
Expand All @@ -331,6 +335,7 @@ class FireCrawl_DocumentLoaders implements INode {
url,
mode: crawlerType as 'crawl' | 'scrape',
apiKey: firecrawlApiToken,
apiUrl: firecrawlApiUrl,
params: {
crawlerOptions: {
includes: urlPatternsIncludes,
Expand All @@ -344,7 +349,6 @@ class FireCrawl_DocumentLoaders implements INode {
}
}
}

const loader = new FireCrawlLoader(input)

let docs = []
Expand Down
Loading