Skip to content

Commit

Permalink
feat: ScrapeGraph AI component updates and add new component Scrapgra…
Browse files Browse the repository at this point in the history
…phSearch API (#6305)

* feat: add search

* Update __init__.py

* Update pyproject.toml

* feat: update scraegraph components

* Update scrapegraph_smart_scraper_api.py

* Update scrapegraph_smart_scraper_api.py

* removed required

* Update scrapegraph_smart_scraper_api.py

* formatting
  • Loading branch information
VinciGit00 authored Feb 12, 2025
1 parent ec445ce commit 898775c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ dependencies = [
"mcp>=0.9.1",
"uv>=0.5.7",
"ag2>=0.1.0",
"scrapegraph-py>=1.10.2",
"scrapegraph-py>=1.12.0",
"pydantic-ai>=0.0.19",
]

Expand Down
3 changes: 2 additions & 1 deletion src/backend/base/langflow/components/scrapegraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .scrapegraph_markdownify_api import ScrapeGraphMarkdownifyApi
from .scrapegraph_search_api import ScrapeGraphSearchApi
from .scrapegraph_smart_scraper_api import ScrapeGraphSmartScraperApi

__all__ = ["ScrapeGraphMarkdownifyApi", "ScrapeGraphSmartScraperApi"]
__all__ = ["ScrapeGraphMarkdownifyApi", "ScrapeGraphSearchApi", "ScrapeGraphSmartScraperApi"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from langflow.custom import Component
from langflow.io import (
MessageTextInput,
Output,
SecretStrInput,
StrInput,
)
from langflow.schema import Data

Expand All @@ -25,10 +25,10 @@ class ScrapeGraphMarkdownifyApi(Component):
password=True,
info="The API key to use ScrapeGraph API.",
),
StrInput(
MessageTextInput(
name="url",
display_name="URL",
required=True,
tool_mode=True,
info="The URL to markdownify.",
),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from langflow.custom import Component
from langflow.io import (
MessageTextInput,
Output,
SecretStrInput,
)
from langflow.schema import Data


class ScrapeGraphSearchApi(Component):
display_name: str = "ScrapeGraphSearchApi"
description: str = """ScrapeGraph Search API.
Given a search prompt, it will return search results using ScrapeGraph's search functionality.
More info at https://docs.scrapegraphai.com/services/searchscraper"""
name = "ScrapeGraphSearchApi"

documentation: str = "https://docs.scrapegraphai.com/introduction"
icon = "ScrapeGraph"

inputs = [
SecretStrInput(
name="api_key",
display_name="ScrapeGraph API Key",
required=True,
password=True,
info="The API key to use ScrapeGraph API.",
),
MessageTextInput(
name="user_prompt",
display_name="Search Prompt",
tool_mode=True,
info="The search prompt to use.",
),
]

outputs = [
Output(display_name="Data", name="data", method="search"),
]

def search(self) -> list[Data]:
try:
from scrapegraph_py import Client
from scrapegraph_py.logger import sgai_logger
except ImportError as e:
msg = "Could not import scrapegraph-py package. Please install it with `pip install scrapegraph-py`."
raise ImportError(msg) from e

# Set logging level
sgai_logger.set_logging(level="INFO")

# Initialize the client with API key
sgai_client = Client(api_key=self.api_key)

try:
# SearchScraper request
response = sgai_client.searchscraper(
user_prompt=self.user_prompt,
)

# Close the client
sgai_client.close()

return Data(data=response)
except Exception:
sgai_client.close()
raise
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from langflow.custom import Component
from langflow.io import (
MessageTextInput,
Output,
SecretStrInput,
StrInput,
)
from langflow.schema import Data

Expand All @@ -25,12 +25,18 @@ class ScrapeGraphSmartScraperApi(Component):
password=True,
info="The API key to use ScrapeGraph API.",
),
StrInput(
MessageTextInput(
name="url",
display_name="URL",
required=True,
tool_mode=True,
info="The URL to scrape.",
),
MessageTextInput(
name="prompt",
display_name="Prompt",
tool_mode=True,
info="The prompt to use for the smart scraper.",
),
]

outputs = [
Expand All @@ -55,6 +61,7 @@ def scrape(self) -> list[Data]:
# SmartScraper request
response = sgai_client.smartscraper(
website_url=self.url,
user_prompt=self.prompt,
)

# Close the client
Expand Down
44 changes: 22 additions & 22 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 898775c

Please sign in to comment.