MPJL commited on
Commit
ac09612
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

Addition of a tool to get the weather in a given city

Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -18,6 +18,21 @@ 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(city: str) -> str:
23
+ import requests
24
+ """A tool that gives the current weather in a city
25
+ Args:
26
+ arg1: city name
27
+ """
28
+ api_url = f"https://api.weather.com/v1/location/{city}?apiKey=YOUR_API_KEY"
29
+ response = requests.get(api_url)
30
+ if response.status_code == 200:
31
+ data = response.json()
32
+ return data.get("weather", "No weather information available")
33
+ else:
34
+ return "Error: Unable to fetch weather data."
35
+
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
38
  """A tool that fetches the current local time in a specified timezone.