-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Added firecrawl as a toolcall to crawl website contents from url #1797
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
Changes from 2 commits
47b20b3
2b43d82
6c05577
db20380
793342e
3ee56d4
3857b50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import FirecrawlApp from '@mendable/firecrawl-js'; | ||
|
||
export interface CrawlOptions { | ||
limit?: number; | ||
scrapeOptions?: { | ||
formats?: ( | ||
| 'markdown' | ||
| 'html' | ||
| 'rawHtml' | ||
| 'content' | ||
| 'links' | ||
| 'screenshot' | ||
| 'screenshot@fullPage' | ||
| 'extract' | ||
| 'json' | ||
| 'changeTracking' | ||
)[]; | ||
}; | ||
} | ||
|
||
export class CrawlerService { | ||
private static instance: CrawlerService; | ||
|
||
private app: FirecrawlApp; | ||
|
||
private constructor() { | ||
this.app = new FirecrawlApp({ apiKey: process.env.VITE_FIRECRAWL_API_KEY }); | ||
} | ||
|
||
static getInstance(): CrawlerService { | ||
if (!this.instance) { | ||
this.instance = new CrawlerService(); | ||
} | ||
return this.instance; | ||
} | ||
|
||
async crawlUrl( | ||
url: string, | ||
options: CrawlOptions = { | ||
limit: 100, | ||
scrapeOptions: { | ||
formats: ['markdown', 'html'], | ||
}, | ||
}, | ||
) { | ||
try { | ||
const response = await this.app.crawlUrl(url, options); | ||
|
||
if (!response.success) { | ||
throw new Error(`Failed to crawl: ${response.error}`); | ||
} | ||
return response; | ||
} catch (error) { | ||
console.error('Error during crawling:', error); | ||
throw error; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,8 @@ import { useEffect, useRef, useState } from 'react'; | |||||
import useResizeObserver from 'use-resize-observer'; | ||||||
import { DraftImagePill } from '../../editor/EditPanel/ChatTab/ContextPills/DraftingImagePill'; | ||||||
import { useTranslation } from 'react-i18next'; | ||||||
import { CrawlerService } from '@/lib/services/crawler'; | ||||||
import { toast } from '@onlook/ui/use-toast'; | ||||||
|
||||||
export const PromptingCard = () => { | ||||||
const projectsManager = useProjectsManager(); | ||||||
|
@@ -28,6 +30,9 @@ export const PromptingCard = () => { | |||||
const [isComposing, setIsComposing] = useState(false); | ||||||
const imageRef = useRef<HTMLInputElement>(null); | ||||||
const { t } = useTranslation(); | ||||||
const [urlInput, setUrlInput] = useState(''); | ||||||
const [isCrawling, setIsCrawling] = useState(false); | ||||||
const [crawledValue, setCrawledValue] = useState(''); | ||||||
|
||||||
useEffect(() => { | ||||||
const handleEscapeKey = (e: KeyboardEvent) => { | ||||||
|
@@ -45,11 +50,11 @@ export const PromptingCard = () => { | |||||
console.warn('Input is too short'); | ||||||
return; | ||||||
} | ||||||
projectsManager.create.sendPrompt(inputValue, selectedImages, false); | ||||||
projectsManager.create.sendPrompt(inputValue, selectedImages, crawledValue, false); | ||||||
SoloDevAbu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
}; | ||||||
|
||||||
const handleBlankSubmit = async () => { | ||||||
projectsManager.create.sendPrompt('', [], true); | ||||||
projectsManager.create.sendPrompt('', [], '', true); | ||||||
}; | ||||||
|
||||||
const handleDragOver = (e: React.DragEvent) => { | ||||||
|
@@ -179,6 +184,62 @@ export const PromptingCard = () => { | |||||
} | ||||||
}; | ||||||
|
||||||
const handleCrawlSubmit = async () => { | ||||||
if (!urlInput.trim()) { | ||||||
SoloDevAbu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
console.warn('URL input is empty'); | ||||||
|
console.warn('URL input is empty'); | |
toast({ title: 'URL Required', description: 'Please enter a URL before submitting.', variant: 'destructive' }); |
SoloDevAbu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
Consider validating the structure of the crawled response (e.g., ensuring response.data
is an array with expected 'html' and 'markdown' properties) before using it.
Uh oh!
There was an error while loading. Please reload this page.