saishravan commited on
Commit
60c7974
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -33,6 +33,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def get_weather(city: str) -> str:
38
+ """Get current weather of a given city using OpenWeatherMap API.
39
+ Args:
40
+ city: The city for which to fetch the weather (e.g., 'London')
41
+ """
42
+ try:
43
+ # Replace YOUR_API_KEY with a real one from https://openweathermap.org/api
44
+ API_KEY = "abeae33cc4354d97bccd7222871e6074"
45
+ url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric"
46
+ response = requests.get(url)
47
+ data = response.json()
48
+
49
+ if data.get("cod") != 200:
50
+ return f"Failed to get weather: {data.get('message', '')}"
51
+
52
+ weather = data["weather"][0]["description"]
53
+ temp = data["main"]["temp"]
54
+ return f"The current weather in {city} is {weather} with temperature {temp}°C"
55
+ except Exception as e:
56
+ return f"Error: {str(e)}"
57
+
58
 
59
  final_answer = FinalAnswerTool()
60
 
 
77
 
78
  agent = CodeAgent(
79
  model=model,
80
+ tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
81
  max_steps=6,
82
  verbosity_level=1,
83
  grammar=None,