MasterOfHugs commited on
Commit
a57b64d
·
verified ·
1 Parent(s): 24249d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,5 +1,7 @@
1
  from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
  from duckduckgo_search import DDGS
 
 
3
  import datetime
4
  import pytz
5
  import yaml
@@ -60,6 +62,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
60
  except Exception as e:
61
  return f"Erreur pour le fuseau horaire '{timezone}': {str(e)}"
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  #---------------------------------------------------------------------------
64
  #---------------------------------------------------------------------------init
65
  #---------------------------------------------------------------------------
@@ -84,7 +103,8 @@ agent = CodeAgent(
84
  final_answer,
85
  get_stock_price,
86
  get_current_time_in_timezone,
87
- web_search
 
88
  ],
89
  max_steps=6,
90
  verbosity_level=1,
 
1
  from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
  from duckduckgo_search import DDGS
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
  import datetime
6
  import pytz
7
  import yaml
 
62
  except Exception as e:
63
  return f"Erreur pour le fuseau horaire '{timezone}': {str(e)}"
64
 
65
+ #visit webpage
66
+ @tool
67
+ def visit_webpage(url: str) -> str:
68
+ """Visite une page web et retourne son texte brut (HTML simplifié).
69
+ Args:
70
+ url: L’URL de la page à visiter.
71
+ """
72
+ try:
73
+ headers = {"User-Agent": "Mozilla/5.0 (compatible; AgentBot/1.0)"}
74
+ response = requests.get(url, headers=headers, timeout=10)
75
+ response.raise_for_status()
76
+ soup = BeautifulSoup(response.text, "html.parser")
77
+ text = soup.get_text(separator="\n", strip=True)
78
+ return json.dumps({"url": url, "content": text[:5000]}) # limite la taille
79
+ except Exception as e:
80
+ return json.dumps({"error": str(e)})
81
+
82
  #---------------------------------------------------------------------------
83
  #---------------------------------------------------------------------------init
84
  #---------------------------------------------------------------------------
 
103
  final_answer,
104
  get_stock_price,
105
  get_current_time_in_timezone,
106
+ web_search,
107
+ visit_webpage
108
  ],
109
  max_steps=6,
110
  verbosity_level=1,