subham73 commited on
Commit
48dc980
·
verified ·
1 Parent(s): cdf6b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -17,14 +17,15 @@ def current_weather(location: str)-> str:
17
  Returns:
18
  str: Weather description and temperature of the specified location
19
  """
20
-
21
- key = "4da8241f3e302b39314e95cf04d4552e"
22
- url = f"https://api.weatherstack.com/current?access_key={key}"
23
- query = {"query": location}
24
- response = requests.get(url, params=query)
25
- data = response.json()
26
- return f"Weather of {location} is {data['current']['weather_descriptions']} with the temperature {data['current']['temperature']}"
27
-
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
30
  """A tool that fetches the current local time in a specified timezone.
 
17
  Returns:
18
  str: Weather description and temperature of the specified location
19
  """
20
+ try:
21
+ key = "4da8241f3e302b39314e95cf04d4552e"
22
+ url = f"https://api.weatherstack.com/current?access_key={key}"
23
+ query = {"query": location}
24
+ response = requests.get(url, params=query)
25
+ data = response.json()
26
+ return f"Weather of {location} is {data['current']['weather_descriptions']} with the temperature {data['current']['temperature']}"
27
+ except Exception as e:
28
+ return f"Error fetching weather for ''{location': str{e}}"
29
  @tool
30
  def get_current_time_in_timezone(timezone: str) -> str:
31
  """A tool that fetches the current local time in a specified timezone.