Kserus commited on
Commit
16ad0c0
·
verified ·
1 Parent(s): 3fda0e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -18,6 +18,42 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_weather(location: str) -> str:
23
+ """Get current weather information for a specified location.
24
+ Args:
25
+ location: City name and optionally country code (e.g., 'London' or 'London,UK')
26
+ """
27
+ try:
28
+ # Replace with your actual API key
29
+ API_KEY = "de1f560f2d4bea4e02dcdbe2e6f197a6"
30
+ base_url = "http://api.openweathermap.org/data/2.5/weather"
31
+
32
+ params = {
33
+ 'q': location,
34
+ 'appid': API_KEY,
35
+ 'units': 'metric' # for Celsius, use 'imperial' for Fahrenheit
36
+ }
37
+
38
+ response = requests.get(base_url, params=params)
39
+ data = response.json()
40
+
41
+ if response.status_code == 200:
42
+ weather = data['weather'][0]['description']
43
+ temp = data['main']['temp']
44
+ feels_like = data['main']['feels_like']
45
+ humidity = data['main']['humidity']
46
+ wind_speed = data['wind']['speed']
47
+
48
+ return (f"Weather in {location}: {weather}. "
49
+ f"Temperature: {temp}°C (feels like {feels_like}°C), "
50
+ f"Humidity: {humidity}%, Wind: {wind_speed} m/s")
51
+ else:
52
+ return f"Error getting weather: {data.get('message', 'Unknown error')}"
53
+
54
+ except Exception as e:
55
+ return f"Error fetching weather data: {str(e)}"
56
+
57
  @tool
58
  def get_current_time_in_timezone(timezone: str) -> str:
59
  """A tool that fetches the current local time in a specified timezone.