micposso commited on
Commit
bc40562
·
verified ·
1 Parent(s): 251c915

add a tool

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -8,15 +8,40 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity!
 
 
 
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
13
- # Keep this format for the tool description / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
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:
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity!
11
+ import requests
12
+ from smolagents import tool
13
+
14
  @tool
15
+ def city_team_weather(city: str, team: str) -> str:
16
+ """
17
+ Provides a fun weather-and-sports mashup based on the city and team name.
18
+
19
  Args:
20
+ city: The city to get the weather for (e.g., "Boston")
21
+ team: The sports team name (e.g., "Red Sox")
22
  """
23
+ try:
24
+ # Use Open-Meteo API (no API key required for basic access)
25
+ url = f"https://api.open-meteo.com/v1/forecast?latitude=0&longitude=0&current_weather=true"
26
+ geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
27
+
28
+ geo_resp = requests.get(geo_url).json()
29
+ if not geo_resp.get("results"):
30
+ return f"Could not find weather data for {city}."
31
+
32
+ lat = geo_resp["results"][0]["latitude"]
33
+ lon = geo_resp["results"][0]["longitude"]
34
+
35
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
36
+ weather_resp = requests.get(weather_url).json()
37
+ weather = weather_resp["current_weather"]["temperature"]
38
+
39
+ return (
40
+ f"In {city}, it's currently {weather}°C. "
41
+ f"The {team} are heating up too—maybe it's the weather, maybe it's just game day vibes!"
42
+ )
43
+ except Exception as e:
44
+ return f"Error retrieving data: {str(e)}"
45
 
46
  @tool
47
  def get_current_time_in_timezone(timezone: str) -> str: