Skip to content

Commit 1f8f7d8

Browse files
authored
feat: add search endpoint for Firecrawl Integration (#87)
1 parent 9069046 commit 1f8f7d8

File tree

1 file changed

+8
-6
lines changed
  • libs/community/langchain_community/document_loaders

1 file changed

+8
-6
lines changed

libs/community/langchain_community/document_loaders/firecrawl.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __init__(
226226
*,
227227
api_key: Optional[str] = None,
228228
api_url: Optional[str] = None,
229-
mode: Literal["crawl", "scrape", "map", "extract"] = "crawl",
229+
mode: Literal["crawl", "scrape", "map", "extract", "search"] = "crawl",
230230
params: Optional[dict] = None,
231231
):
232232
"""Initialize with API key and url.
@@ -242,6 +242,7 @@ def __init__(
242242
"crawl" (all accessible sub pages),
243243
"map" (returns list of links that are semantically related).
244244
"extract" (extracts structured data from a page).
245+
"search" (search for data across the web).
245246
params: The parameters to pass to the Firecrawl API.
246247
Examples include crawlerOptions.
247248
For more details, visit: https://github.com/mendableai/firecrawl-py
@@ -253,10 +254,10 @@ def __init__(
253254
raise ImportError(
254255
"`firecrawl` package not found, please run `pip install firecrawl-py`"
255256
)
256-
if mode not in ("crawl", "scrape", "search", "map", "extract"):
257+
if mode not in ("crawl", "scrape", "search", "map", "extract", "search"):
257258
raise ValueError(
258259
f"""Invalid mode '{mode}'.
259-
Allowed: 'crawl', 'scrape', 'search', 'map', 'extract'."""
260+
Allowed: 'crawl', 'scrape', 'search', 'map', 'extract', 'search'."""
260261
)
261262

262263
if not url:
@@ -293,13 +294,14 @@ def lazy_load(self) -> Iterator[Document]:
293294
str(self.firecrawl.extract([self.url], params=self.params))
294295
]
295296
elif self.mode == "search":
296-
raise ValueError(
297-
"Search mode is not supported in this version, please downgrade."
297+
firecrawl_docs = self.firecrawl.search(
298+
query=self.params.get("query"),
299+
params=self.params,
298300
)
299301
else:
300302
raise ValueError(
301303
f"""Invalid mode '{self.mode}'.
302-
Allowed: 'crawl', 'scrape', 'map', 'extract'."""
304+
Allowed: 'crawl', 'scrape', 'map', 'extract', 'search'."""
303305
)
304306
for doc in firecrawl_docs:
305307
if self.mode == "map" or self.mode == "extract":

0 commit comments

Comments
 (0)