feat: ScrapeGraph AI component updates and add new component ScrapgraphSearch 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
This commit is contained in:
parent
ec445ce7df
commit
898775c36d
6 changed files with 104 additions and 30 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from langflow.custom import Component
|
||||
from langflow.io import (
|
||||
MessageTextInput,
|
||||
Output,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
from langflow.schema import Data
|
||||
|
||||
|
|
@ -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.",
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
from langflow.custom import Component
|
||||
from langflow.io import (
|
||||
MessageTextInput,
|
||||
Output,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
from langflow.schema import Data
|
||||
|
||||
|
|
@ -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 = [
|
||||
|
|
@ -55,6 +61,7 @@ class ScrapeGraphSmartScraperApi(Component):
|
|||
# SmartScraper request
|
||||
response = sgai_client.smartscraper(
|
||||
website_url=self.url,
|
||||
user_prompt=self.prompt,
|
||||
)
|
||||
|
||||
# Close the client
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue