Skip to content
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

feat: ScrapeGraph AI component updates and add new component ScrapgraphSearch API #6305

Merged
merged 9 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,66 @@
from langflow.custom import Component
from langflow.io import (
Output,
SecretStrInput,
StrInput,
)
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"

output_types: list[str] = ["Document"]
documentation: str = "https://docs.scrapegraphai.com/introduction"

inputs = [
SecretStrInput(
name="api_key",
display_name="ScrapeGraph API Key",
required=True,
password=True,
info="The API key to use ScrapeGraph API.",
),
StrInput(
name="user_prompt",
display_name="Search Prompt",
required=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
Loading