-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ScrapeGraphAI/pre/beta
Pre/beta
- Loading branch information
Showing
7 changed files
with
247 additions
and
17 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
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,38 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel, Field | ||
from scrapegraph_py.logger import sgai_logger | ||
|
||
from langchain_scrapegraph.tools import LocalScraperTool | ||
|
||
|
||
class WebsiteInfo(BaseModel): | ||
title: str = Field(description="The main title of the webpage") | ||
description: str = Field(description="The main description or first paragraph") | ||
urls: List[str] = Field(description="The URLs inside the webpage") | ||
|
||
|
||
sgai_logger.set_logging(level="INFO") | ||
|
||
# Initialize with Pydantic model class | ||
tool = LocalScraperTool(llm_output_schema=WebsiteInfo) | ||
|
||
# Example website and prompt | ||
html_content = """ | ||
<html> | ||
<body> | ||
<h1>Company Name</h1> | ||
<p>We are a technology company focused on AI solutions.</p> | ||
<div class="contact"> | ||
<p>Email: contact@example.com</p> | ||
<p>Phone: (555) 123-4567</p> | ||
</div> | ||
</body> | ||
</html> | ||
""" | ||
user_prompt = "Make a summary of the webpage and extract the email and phone number" | ||
|
||
# Use the tool | ||
result = tool.invoke({"website_html": html_content, "user_prompt": user_prompt}) | ||
|
||
print(result) |
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,26 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel, Field | ||
from scrapegraph_py.logger import sgai_logger | ||
|
||
from langchain_scrapegraph.tools import SmartScraperTool | ||
|
||
|
||
class WebsiteInfo(BaseModel): | ||
title: str = Field(description="The main title of the webpage") | ||
description: str = Field(description="The main description or first paragraph") | ||
urls: List[str] = Field(description="The URLs inside the webpage") | ||
|
||
|
||
sgai_logger.set_logging(level="INFO") | ||
|
||
# Initialize with Pydantic model class | ||
tool = SmartScraperTool(llm_output_schema=WebsiteInfo) | ||
|
||
# Example website and prompt | ||
website_url = "https://www.example.com" | ||
user_prompt = "Extract info about the website" | ||
|
||
# Use the tool - output will conform to WebsiteInfo schema | ||
result = tool.invoke({"website_url": website_url, "user_prompt": user_prompt}) | ||
print(result) |
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
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