Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -17,6 +17,34 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
17
  arg2: the second argument
18
  """
19
  return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
1
+ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool,search_hotels
2
  import datetime
3
  import requests
4
  import pytz
 
17
  arg2: the second argument
18
  """
19
  return "What magic will you build ?"
20
+ @tool
21
+ def search_hotels(location: str) -> str:
22
+ """
23
+ Search for economical 4- and 5-star hotels in a given location using DuckDuckGo.
24
+
25
+ Args:
26
+ location: The city or destination to search for hotels in.
27
+
28
+ Returns:
29
+ A string listing a few hotel results with titles and links.
30
+ """
31
+ query = f"economical 4 and 5 star hotels in {location}"
32
+ url = f"https://lite.duckduckgo.com/lite/?q={query.replace(' ', '+')}"
33
+
34
+ headers = {
35
+ "User-Agent": "Mozilla/5.0"
36
+ }
37
+
38
+ response = requests.get(url, headers=headers)
39
+ soup = BeautifulSoup(response.text, "html.parser")
40
+
41
+ results = []
42
+ for link in soup.select("a.result-link")[:5]:
43
+ title = link.get_text()
44
+ href = link.get("href")
45
+ results.append(f"{title}\n{href}")
46
+
47
+ return "\n\n".join(results) if results else "No hotels found."
48
 
49
  @tool
50
  def get_current_time_in_timezone(timezone: str) -> str: