Realistvik0 commited on
Commit
2182f0a
·
verified ·
1 Parent(s): ffd4fdf

Update tools/visit_webpage.py

Browse files
Files changed (1) hide show
  1. tools/visit_webpage.py +7 -3
tools/visit_webpage.py CHANGED
@@ -11,6 +11,10 @@ class VisitWebpageTool(Tool):
11
  inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
12
  output_type = "string"
13
 
 
 
 
 
14
  def forward(self, url: str) -> str:
15
  try:
16
  import requests
@@ -23,8 +27,8 @@ class VisitWebpageTool(Tool):
23
  "You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`."
24
  ) from e
25
  try:
26
- # Send a GET request to the URL with a 20-second timeout
27
- response = requests.get(url, timeout=20)
28
  response.raise_for_status() # Raise an exception for bad status codes
29
 
30
  # Convert the HTML content to Markdown
@@ -43,4 +47,4 @@ class VisitWebpageTool(Tool):
43
  return f"An unexpected error occurred: {str(e)}"
44
 
45
  def __init__(self, *args, **kwargs):
46
- self.is_initialized = False
 
11
  inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
12
  output_type = "string"
13
 
14
+ HEADERS = {
15
+ "User-Agent": "Mozilla/5.0 (compatible; ResearchAgent/1.0; +https://huggingface.co/spaces/Realistvik0/First_agent_template)"
16
+ }
17
+
18
  def forward(self, url: str) -> str:
19
  try:
20
  import requests
 
27
  "You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`."
28
  ) from e
29
  try:
30
+ # Send a GET request to the URL with a real User-Agent and a 20-second timeout
31
+ response = requests.get(url, headers=self.HEADERS, timeout=20)
32
  response.raise_for_status() # Raise an exception for bad status codes
33
 
34
  # Convert the HTML content to Markdown
 
47
  return f"An unexpected error occurred: {str(e)}"
48
 
49
  def __init__(self, *args, **kwargs):
50
+ self.is_initialized = False