# Pull Request Template ## Description - Fetch main content only from Firecrawl, exclude some tags to remove boilerplate - Prompt changes for FAQ generation ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. tested locally ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
60 lines
1.3 KiB
Ruby
60 lines
1.3 KiB
Ruby
class Captain::Tools::FirecrawlService
|
|
BASE_URL = 'https://api.firecrawl.dev/v1'.freeze
|
|
FIRECRAWL_EXCLUDE_TAGS = %w[iframe .sidebar .cookie-banner [role=navigation] [role=banner] [role=contentinfo]].freeze
|
|
|
|
def initialize
|
|
@api_key = InstallationConfig.find_by!(name: 'CAPTAIN_FIRECRAWL_API_KEY').value
|
|
raise 'Missing API key' if @api_key.empty?
|
|
end
|
|
|
|
def perform(url, webhook_url, crawl_limit = 10)
|
|
HTTParty.post(
|
|
"#{BASE_URL}/crawl",
|
|
body: crawl_payload(url, webhook_url, crawl_limit),
|
|
headers: headers
|
|
)
|
|
rescue StandardError => e
|
|
raise "Failed to crawl URL: #{e.message}"
|
|
end
|
|
|
|
def scrape(url)
|
|
HTTParty.post(
|
|
"#{BASE_URL}/scrape",
|
|
body: scrape_payload(url),
|
|
headers: headers
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def crawl_payload(url, webhook_url, crawl_limit)
|
|
{
|
|
url: url,
|
|
maxDepth: 50,
|
|
ignoreSitemap: false,
|
|
limit: crawl_limit,
|
|
webhook: webhook_url,
|
|
scrapeOptions: scrape_options
|
|
}.to_json
|
|
end
|
|
|
|
def scrape_payload(url)
|
|
{ url: url }.merge(scrape_options).to_json
|
|
end
|
|
|
|
def scrape_options
|
|
{
|
|
onlyMainContent: true,
|
|
formats: ['markdown'],
|
|
excludeTags: FIRECRAWL_EXCLUDE_TAGS
|
|
}
|
|
end
|
|
|
|
def headers
|
|
{
|
|
'Authorization' => "Bearer #{@api_key}",
|
|
'Content-Type' => 'application/json'
|
|
}
|
|
end
|
|
end
|