Spaces:
Runtime error
Runtime error
Update tools/visit_webpage.py
Browse files- tools/visit_webpage.py +6 -8
tools/visit_webpage.py
CHANGED
|
@@ -3,6 +3,7 @@ from smolagents.tools import Tool
|
|
| 3 |
import requests
|
| 4 |
import markdownify
|
| 5 |
import smolagents
|
|
|
|
| 6 |
|
| 7 |
class VisitWebpageTool(Tool):
|
| 8 |
name = "visit_webpage"
|
|
@@ -10,6 +11,10 @@ class VisitWebpageTool(Tool):
|
|
| 10 |
inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
|
| 11 |
output_type = "string"
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def forward(self, url: str) -> str:
|
| 14 |
try:
|
| 15 |
import requests
|
|
@@ -35,11 +40,4 @@ class VisitWebpageTool(Tool):
|
|
| 35 |
return truncate_content(markdown_content, 10000)
|
| 36 |
|
| 37 |
except requests.exceptions.Timeout:
|
| 38 |
-
return
|
| 39 |
-
except RequestException as e:
|
| 40 |
-
return f"Error fetching the webpage: {str(e)}"
|
| 41 |
-
except Exception as e:
|
| 42 |
-
return f"An unexpected error occurred: {str(e)}"
|
| 43 |
-
|
| 44 |
-
def __init__(self, *args, **kwargs):
|
| 45 |
-
self.is_initialized = False
|
|
|
|
| 3 |
import requests
|
| 4 |
import markdownify
|
| 5 |
import smolagents
|
| 6 |
+
import re # Import the re module for regular expressions
|
| 7 |
|
| 8 |
class VisitWebpageTool(Tool):
|
| 9 |
name = "visit_webpage"
|
|
|
|
| 11 |
inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
|
| 12 |
output_type = "string"
|
| 13 |
|
| 14 |
+
def __init__(self, *args, **kwargs):
|
| 15 |
+
super().__init__(*args, **kwargs)
|
| 16 |
+
self.is_initialized = True # Example initialization logic
|
| 17 |
+
|
| 18 |
def forward(self, url: str) -> str:
|
| 19 |
try:
|
| 20 |
import requests
|
|
|
|
| 40 |
return truncate_content(markdown_content, 10000)
|
| 41 |
|
| 42 |
except requests.exceptions.Timeout:
|
| 43 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|