added firecrawl integration
This commit is contained in:
parent
8eae0c5df7
commit
d4c18d3c00
10 changed files with 291 additions and 7 deletions
|
|
@ -0,0 +1,81 @@
|
|||
from typing import Optional
|
||||
from firecrawl.firecrawl import FirecrawlApp
|
||||
from langflow.custom import CustomComponent
|
||||
from langflow.schema import Data
|
||||
import uuid
|
||||
|
||||
class FirecrawlCrawlApi(CustomComponent):
|
||||
display_name: str = "FirecrawlCrawlApi"
|
||||
description: str = "Firecrawl Crawl API."
|
||||
output_types: list[str] = ["Document"]
|
||||
documentation: str = "https://docs.firecrawl.dev/api-reference/endpoint/crawl"
|
||||
field_config = {
|
||||
"api_key": {
|
||||
"display_name": "API Key",
|
||||
"field_type": "str",
|
||||
"required": True,
|
||||
"password": True,
|
||||
"info": "The API key to use Firecrawl API.",
|
||||
},
|
||||
"url": {
|
||||
"display_name": "URL",
|
||||
"field_type": "str",
|
||||
"required": True,
|
||||
"info": "The base URL to start crawling from.",
|
||||
},
|
||||
"timeout": {
|
||||
"display_name": "Timeout",
|
||||
"field_type": "int",
|
||||
"info": "The timeout in milliseconds.",
|
||||
},
|
||||
"crawlerOptions": {
|
||||
"display_name": "Crawler Options",
|
||||
"info": "Options for the crawler behavior.",
|
||||
},
|
||||
"pageOptions": {
|
||||
"display_name": "Page Options",
|
||||
"info": "The page options to send with the request.",
|
||||
},
|
||||
"idempotency_key": {
|
||||
"display_name": "Idempotency Key",
|
||||
"field_type": "str",
|
||||
"info": "Optional idempotency key to ensure unique requests.",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
api_key: str,
|
||||
url: str,
|
||||
timeout: Optional[int] = 30000,
|
||||
crawlerOptions: Optional[Data] = None,
|
||||
pageOptions: Optional[Data] = None,
|
||||
idempotency_key: Optional[str] = None,
|
||||
) -> Data:
|
||||
if crawlerOptions:
|
||||
crawler_options_dict = crawlerOptions.__dict__['data']['text']
|
||||
else:
|
||||
crawler_options_dict = {}
|
||||
|
||||
if pageOptions:
|
||||
page_options_dict = pageOptions.__dict__['data']['text']
|
||||
else:
|
||||
page_options_dict = {}
|
||||
|
||||
if not idempotency_key:
|
||||
idempotency_key = str(uuid.uuid4())
|
||||
|
||||
app = FirecrawlApp(api_key=api_key)
|
||||
crawl_result = app.crawl_url(
|
||||
url,
|
||||
{
|
||||
"crawlerOptions": crawler_options_dict,
|
||||
"pageOptions": page_options_dict,
|
||||
},
|
||||
True,
|
||||
int(timeout / 1000),
|
||||
idempotency_key
|
||||
)
|
||||
|
||||
records = Data(data={"results": crawl_result})
|
||||
return records
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
from typing import Optional
|
||||
from firecrawl.firecrawl import FirecrawlApp
|
||||
from langflow.custom import CustomComponent
|
||||
from langflow.schema import Data
|
||||
from langflow.services.database.models.base import orjson_dumps
|
||||
import json
|
||||
|
||||
class FirecrawlScrapeApi(CustomComponent):
|
||||
display_name: str = "FirecrawlScrapeApi"
|
||||
description: str = "Firecrawl Scrape API."
|
||||
output_types: list[str] = ["Document"]
|
||||
documentation: str = "https://docs.firecrawl.dev/api-reference/endpoint/scrape"
|
||||
field_config = {
|
||||
"api_key": {
|
||||
"display_name": "API Key",
|
||||
"field_type": "str",
|
||||
"required": True,
|
||||
"password": True,
|
||||
"info": "The API key to use Firecrawl API.",
|
||||
},
|
||||
"url": {
|
||||
"display_name": "URL",
|
||||
"field_type": "str",
|
||||
"required": True,
|
||||
"info": "The URL to scrape.",
|
||||
},
|
||||
"timeout": {
|
||||
"display_name": "Timeout",
|
||||
"info": "Timeout in milliseconds for the request.",
|
||||
"field_type": "int",
|
||||
"default_value": 10000,
|
||||
},
|
||||
"pageOptions": {
|
||||
"display_name": "Page Options",
|
||||
"info": "The page options to send with the request.",
|
||||
},
|
||||
"extractorOptions": {
|
||||
"display_name": "Extractor Options",
|
||||
"info": "The extractor options to send with the request.",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
api_key: str,
|
||||
url: str,
|
||||
timeout: Optional[int] = 10000,
|
||||
pageOptions: Optional[Data] = None,
|
||||
extractorOptions: Optional[Data] = None,
|
||||
) -> Data:
|
||||
if extractorOptions:
|
||||
extractor_options_dict = extractorOptions.__dict__['data']['text']
|
||||
else:
|
||||
extractor_options_dict = {}
|
||||
|
||||
if pageOptions:
|
||||
page_options_dict = pageOptions.__dict__['data']['text']
|
||||
else:
|
||||
page_options_dict = {}
|
||||
|
||||
app = FirecrawlApp(api_key=api_key)
|
||||
results = app.scrape_url(
|
||||
url,
|
||||
{
|
||||
"timeout": str(timeout),
|
||||
"extractorOptions": extractor_options_dict,
|
||||
"pageOptions": page_options_dict,
|
||||
},
|
||||
)
|
||||
|
||||
record = Data(data=results)
|
||||
return record
|
||||
16
src/backend/base/poetry.lock
generated
16
src/backend/base/poetry.lock
generated
|
|
@ -739,6 +739,20 @@ typer = ">=0.12.3"
|
|||
[package.extras]
|
||||
standard = ["fastapi", "uvicorn[standard] (>=0.15.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "firecrawl-py"
|
||||
version = "0.0.16"
|
||||
description = "Python SDK for Firecrawl API"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "firecrawl_py-0.0.16-py3-none-any.whl", hash = "sha256:9024f483b501852a6b9c4e6cdfc9e8dde452d922afac357080bb278a0c9c2a26"},
|
||||
{file = "firecrawl_py-0.0.16.tar.gz", hash = "sha256:6c662fa0a549bc7f5c0acb704baba6731869ca0451094034264dfc1b4eb086e4"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
requests = "*"
|
||||
|
||||
[[package]]
|
||||
name = "frozenlist"
|
||||
version = "1.4.1"
|
||||
|
|
@ -3232,4 +3246,4 @@ local = []
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.10,<3.13"
|
||||
content-hash = "4f566531a8539ddc81cb91a7e7f9b723c84679f0af5bb8619f7b02f9ffc6cfaa"
|
||||
content-hash = "7e46144d27c633214f00e73e496c0e4d56db1fb47032a21861677ec275b79d86"
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ pyperclip = "^1.8.2"
|
|||
uncurl = "^0.0.11"
|
||||
sentry-sdk = {extras = ["fastapi", "loguru"], version = "^2.5.1"}
|
||||
chardet = "^5.2.0"
|
||||
firecrawl-py = "^0.0.16"
|
||||
|
||||
|
||||
[tool.poetry.extras]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue