-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ScrapeGraph AI component updates and add new component Scrapgra…
…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
1 parent
ec445ce
commit 898775c
Showing
6 changed files
with
104 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/backend/base/langflow/components/scrapegraph/scrapegraph_search_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.