Skip to content

Firecrawl example docs #1438

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 2 commits into from
Oct 30, 2024
Merged

Firecrawl example docs #1438

merged 2 commits into from
Oct 30, 2024

Conversation

D-K-P
Copy link
Member

@D-K-P D-K-P commented Oct 30, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a comprehensive guide on using Firecrawl with Trigger.dev for web crawling and scraping tasks.
    • Added examples for crawling an entire website and scraping a single URL, including error handling and TypeScript code snippets.
    • New navigation entry for the Firecrawl example task in the documentation.
    • Updated the "Example tasks" section in the introduction to include the Firecrawl URL crawl task, enhancing resources for users.

Copy link

changeset-bot bot commented Oct 30, 2024

⚠️ No Changeset found

Latest commit: 9d9372c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

This pull request introduces a new documentation file titled "Crawl a URL using Firecrawl," which serves as a guide for utilizing Firecrawl with Trigger.dev for web crawling and scraping. It includes prerequisites, two main examples demonstrating crawling and scraping tasks, and error handling mechanisms. Additionally, a new entry is added to the navigation structure for easy access to this guide. Two new methods, firecrawlCrawl and firecrawlScrape, are also exported for task execution.

Changes

File Path Change Summary
docs/guides/examples/firecrawl-url-crawl.mdx New documentation file created, detailing how to use Firecrawl with Trigger.dev, including examples and error handling.
docs/mint.json Added a new entry in the "pages" array under "Example tasks" for the new Firecrawl guide.
trigger/firecrawl-url-crawl.ts Added method export const firecrawlCrawl = task(...).
trigger/firecrawl-url-scrape.ts Added method export const firecrawlScrape = task(...).

Possibly related PRs

Suggested reviewers

  • matt-aitken

🐰 In the garden, I hop and play,
With Firecrawl, we’ll find our way!
Scraping URLs, oh what a thrill,
With tasks so easy, we’ll climb the hill.
A guide to share, for all to see,
Let’s crawl the web, just you and me! 🌐✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0840f52 and 9d9372c.

📒 Files selected for processing (1)
  • docs/guides/introduction.mdx (1 hunks)
🔇 Additional comments (1)
docs/guides/introduction.mdx (1)

40-56: LGTM! The new Firecrawl example is well-integrated.

The new example task entry maintains consistent formatting with existing entries and is appropriately placed in alphabetical order. The description is clear and concise.

Let's verify the new documentation link is valid:

✅ Verification successful

Since the fd command successfully found the documentation file at the expected path docs/guides/examples/firecrawl-url-crawl.mdx, I can now verify that the link in the table will work correctly. Let me generate the final response:

The new Firecrawl example entry is correctly added with a valid documentation link

The documentation file exists at the expected path, confirming that the link /guides/examples/firecrawl-url-crawl in the table will work correctly. The entry maintains consistent formatting and proper alphabetical ordering.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Firecrawl documentation file exists
# Expected: File should exist at the specified path

fd "firecrawl-url-crawl.mdx" docs/guides/examples/

Length of output: 95


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
docs/guides/examples/firecrawl-url-crawl.mdx (3)

7-10: Enhance the overview section with more details about Firecrawl's benefits.

Consider expanding the overview to highlight key benefits of using Firecrawl, such as:

  • How the LLM-ready format benefits users
  • What makes Firecrawl different from other crawling solutions
  • Common use cases or scenarios

65-66: Add documentation about the scrape result structure.

The documentation should include:

  1. Example of the returned data structure
  2. Description of available fields
  3. Common usage patterns

Add a section like this:

The `scrapeResult` object includes:
- `success`: Boolean indicating if the scrape was successful
- `data`: Object containing the scraped content in requested formats
  - `markdown`: Clean, formatted markdown content
  - `html`: Original HTML content
- `error`: Error message if the scrape failed

101-103: Enhance the testing section with a complete payload example.

The current example could be more helpful with a complete, realistic payload.

-"url": "<url-to-scrape>" // Replace with the URL you want to scrape
+"url": "https://example.com/blog/post-1"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdcfc81 and 0840f52.

📒 Files selected for processing (2)
  • docs/guides/examples/firecrawl-url-crawl.mdx (1 hunks)
  • docs/mint.json (1 hunks)
🔇 Additional comments (2)
docs/mint.json (2)

373-373: LGTM! The navigation entry is well-structured.

The new entry follows the established naming convention and is correctly positioned within the "Example tasks" section, maintaining alphabetical order.


373-373: Verify the existence of the referenced documentation file.

Let's ensure the referenced documentation file exists at the expected location.

✅ Verification successful

Documentation file exists at the expected location

The referenced documentation file firecrawl-url-crawl.mdx exists at the expected path docs/guides/examples/firecrawl-url-crawl.mdx, confirming that the navigation entry in mint.json is valid.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the Firecrawl documentation file
# Expected: File should exist at docs/guides/examples/firecrawl-url-crawl.mdx

fd -t f "firecrawl-url-crawl.mdx" docs/guides/examples/

Length of output: 100

Comment on lines +37 to +42
const crawlResult = await firecrawlClient.crawlUrl(url, {
limit: 100, // Limit the number of URLs to crawl
scrapeOptions: {
formats: ["markdown", "html"],
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making the limit parameter configurable.

The hard-coded limit of 100 URLs might not suit all use cases. Consider:

  1. Making it a configurable parameter in the payload
  2. Adding documentation about recommended limits
  3. Explaining the implications of different limit values
 const crawlResult = await firecrawlClient.crawlUrl(url, {
-  limit: 100, // Limit the number of URLs to crawl
+  limit: payload.limit ?? 100, // Use provided limit or default to 100
   scrapeOptions: {
     formats: ["markdown", "html"],
   },
 });

Committable suggestion was skipped due to low confidence.

Comment on lines +31 to +52
export const firecrawlCrawl = task({
id: "firecrawl-crawl",
run: async (payload: { url: string }) => {
const { url } = payload;

// Crawl: scrapes all the URLs of a web page and return content in LLM-ready format
const crawlResult = await firecrawlClient.crawlUrl(url, {
limit: 100, // Limit the number of URLs to crawl
scrapeOptions: {
formats: ["markdown", "html"],
},
});

if (!crawlResult.success) {
throw new Error(`Failed to crawl: ${crawlResult.error}`);
}

return {
data: crawlResult,
};
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add type safety and improve error handling.

The implementation could benefit from:

  1. Type definitions for crawlResult
  2. Retry mechanism for transient failures
  3. Documentation about rate limits and error codes
+import { CrawlResponse } from "@mendable/firecrawl-js";
+
 export const firecrawlCrawl = task({
   id: "firecrawl-crawl",
-  run: async (payload: { url: string }) => {
+  run: async (payload: { url: string; limit?: number }) => {
     const { url } = payload;
 
     // Crawl: scrapes all the URLs of a web page and return content in LLM-ready format
-    const crawlResult = await firecrawlClient.crawlUrl(url, {
+    const crawlResult = await firecrawlClient.crawlUrl(url, {
       limit: 100, // Limit the number of URLs to crawl
       scrapeOptions: {
         formats: ["markdown", "html"],
       },
-    });
+    }) as CrawlResponse;

Committable suggestion was skipped due to low confidence.

Comment on lines +82 to +84
const scrapeResult = (await firecrawlClient.scrapeUrl(url, {
formats: ["markdown", "html"],
})) as ScrapeResponse;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid type casting and document the response structure.

The type casting to ScrapeResponse suggests potential type safety issues. Additionally, users would benefit from understanding the structure of the returned data.

-    const scrapeResult = (await firecrawlClient.scrapeUrl(url, {
+    const scrapeResult: ScrapeResponse = await firecrawlClient.scrapeUrl(url, {
       formats: ["markdown", "html"],
-    })) as ScrapeResponse;
+    });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const scrapeResult = (await firecrawlClient.scrapeUrl(url, {
formats: ["markdown", "html"],
})) as ScrapeResponse;
const scrapeResult: ScrapeResponse = await firecrawlClient.scrapeUrl(url, {
formats: ["markdown", "html"],
});

@D-K-P D-K-P merged commit e81b2a7 into main Oct 30, 2024
2 of 3 checks passed
@D-K-P D-K-P deleted the docs/firecrawl branch October 30, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant