Delete tools.py
Browse files
tools.py
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
#from smolagents import Tool
|
| 2 |
-
|
| 3 |
-
###
|
| 4 |
-
from crewai.tools import BaseTool
|
| 5 |
-
from crewai_tools import (
|
| 6 |
-
DirectoryReadTool,
|
| 7 |
-
FileReadTool,
|
| 8 |
-
SerperDevTool,
|
| 9 |
-
WebsiteSearchTool
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
from datetime import date
|
| 13 |
-
###
|
| 14 |
-
|
| 15 |
-
"""
|
| 16 |
-
class VisitWebpageTool(Tool):
|
| 17 |
-
name = "visit_webpage"
|
| 18 |
-
description = (
|
| 19 |
-
"Visits a webpage at the given url and reads its content as a markdown string. Use this to browse webpages."
|
| 20 |
-
)
|
| 21 |
-
inputs = {
|
| 22 |
-
"url": {
|
| 23 |
-
"type": "string",
|
| 24 |
-
"description": "The url of the webpage to visit.",
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
output_type = "string"
|
| 28 |
-
|
| 29 |
-
def forward(self, url: str) -> str:
|
| 30 |
-
try:
|
| 31 |
-
import re
|
| 32 |
-
|
| 33 |
-
import requests
|
| 34 |
-
from markdownify import markdownify
|
| 35 |
-
from requests.exceptions import RequestException
|
| 36 |
-
|
| 37 |
-
from smolagents.utils import truncate_content
|
| 38 |
-
except ImportError as e:
|
| 39 |
-
raise ImportError(
|
| 40 |
-
"You must install packages 'markdownify' and 'requests' to run this tool: for instance run 'pip install markdownify requests'."
|
| 41 |
-
) from e
|
| 42 |
-
try:
|
| 43 |
-
response = requests.get(url, timeout=20)
|
| 44 |
-
response.raise_for_status() # Raise an exception for bad status codes
|
| 45 |
-
markdown_content = markdownify(response.text).strip()
|
| 46 |
-
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 47 |
-
return truncate_content(markdown_content, 40000)
|
| 48 |
-
|
| 49 |
-
except requests.exceptions.Timeout:
|
| 50 |
-
return "The request timed out. Please try again later or check the URL."
|
| 51 |
-
except RequestException as e:
|
| 52 |
-
return f"Error fetching the webpage: {str(e)}"
|
| 53 |
-
except Exception as e:
|
| 54 |
-
return f"An unexpected error occurred: {str(e)}"
|
| 55 |
-
"""
|
| 56 |
-
|
| 57 |
-
###
|
| 58 |
-
class TodayTool(BaseTool):
|
| 59 |
-
name: str ="Today Tool"
|
| 60 |
-
description: str = ("Gets today's date.")
|
| 61 |
-
|
| 62 |
-
def _run(self) -> str:
|
| 63 |
-
return (str(date.today()))
|
| 64 |
-
|
| 65 |
-
def today_tool():
|
| 66 |
-
return TodayTool()
|
| 67 |
-
|
| 68 |
-
def search_tool():
|
| 69 |
-
return SerperDevTool()
|
| 70 |
-
|
| 71 |
-
def scrape_tool():
|
| 72 |
-
return ScrapeWebsiteTool()
|
| 73 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|