Update custom_tools.py
Browse files- custom_tools.py +1 -25
custom_tools.py
CHANGED
@@ -2,7 +2,7 @@ import requests
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
from typing import List, Dict, Any, Type
|
4 |
from functools import lru_cache
|
5 |
-
from smolagents import Tool
|
6 |
from pydantic import BaseModel, Field
|
7 |
|
8 |
class WebpageStructureInputs(BaseModel):
|
@@ -38,30 +38,6 @@ class WebpageStructureAnalyzerTool(Tool):
|
|
38 |
# Ensure the core function is accessible here
|
39 |
return analyze_webpage_structure(url)
|
40 |
|
41 |
-
class CachedWebSearchTool(WebSearchTool):
|
42 |
-
@lru_cache(maxsize=128)
|
43 |
-
def run(self, query: str):
|
44 |
-
# identical queries return instantly
|
45 |
-
return super().run(query)
|
46 |
-
|
47 |
-
class CachedWikiTool(WikipediaSearchTool):
|
48 |
-
@lru_cache(maxsize=128)
|
49 |
-
def run(self, page: str):
|
50 |
-
return super().run(page)
|
51 |
-
|
52 |
-
class PreloadedPythonTool(PythonInterpreterTool):
|
53 |
-
"""
|
54 |
-
A PythonInterpreterTool that automatically prepends the necessary imports
|
55 |
-
(bs4, BeautifulSoup, regex) so you never hit NameError inside your code blocks.
|
56 |
-
"""
|
57 |
-
def run(self, code: str) -> str:
|
58 |
-
preamble = (
|
59 |
-
"import bs4\n"
|
60 |
-
"from bs4 import BeautifulSoup\n"
|
61 |
-
"import regex\n"
|
62 |
-
)
|
63 |
-
return super().run(preamble + code)
|
64 |
-
|
65 |
def analyze_webpage_structure(url: str) -> str:
|
66 |
"""
|
67 |
Fetches a webpage and returns a text summary of its key HTML structure.
|
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
from typing import List, Dict, Any, Type
|
4 |
from functools import lru_cache
|
5 |
+
from smolagents import Tool
|
6 |
from pydantic import BaseModel, Field
|
7 |
|
8 |
class WebpageStructureInputs(BaseModel):
|
|
|
38 |
# Ensure the core function is accessible here
|
39 |
return analyze_webpage_structure(url)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def analyze_webpage_structure(url: str) -> str:
|
42 |
"""
|
43 |
Fetches a webpage and returns a text summary of its key HTML structure.
|