mkashyap commited on
Commit
a0c2416
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -1
app.py CHANGED
@@ -18,6 +18,55 @@ 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.
@@ -55,7 +104,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,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_weather_info(location: str, units: str = "metric") -> str:
23
+ """Get current weather information for a specified location.
24
+
25
+ Args:
26
+ location: City name or location (e.g., 'New York', 'Paris, France')
27
+ units: Unit system to use - 'metric' (Celsius) or 'imperial' (Fahrenheit)
28
+ """
29
+ try:
30
+ # You'll need to sign up for a free API key at OpenWeatherMap
31
+ api_key = "69ac97488cd2eba8412f08c011b01a74"
32
+ base_url = "http://api.openweathermap.org/data/2.5/weather"
33
+
34
+ # Set up the parameters for the API request
35
+ params = {
36
+ "q": location,
37
+ "appid": api_key,
38
+ "units": units
39
+ }
40
+
41
+ # Make the API request
42
+ response = requests.get(base_url, params=params)
43
+ data = response.json()
44
+
45
+ if response.status_code == 200:
46
+ # Extract relevant weather information
47
+ weather_desc = data["weather"][0]["description"]
48
+ temp = data["main"]["temp"]
49
+ feels_like = data["main"]["feels_like"]
50
+ humidity = data["main"]["humidity"]
51
+ wind_speed = data["wind"]["speed"]
52
+
53
+ # Format unit-specific values
54
+ temp_unit = "°C" if units == "metric" else "°F"
55
+ wind_unit = "m/s" if units == "metric" else "mph"
56
+
57
+ # Return formatted weather information
58
+ return f"Weather in {location}:\n" \
59
+ f"Conditions: {weather_desc.capitalize()}\n" \
60
+ f"Temperature: {temp}{temp_unit} (feels like {feels_like}{temp_unit})\n" \
61
+ f"Humidity: {humidity}%\n" \
62
+ f"Wind Speed: {wind_speed} {wind_unit}"
63
+ else:
64
+ return f"Error: Could not retrieve weather for {location}. {data.get('message', 'Unknown error')}"
65
+
66
+ except Exception as e:
67
+ return f"Error fetching weather information: {str(e)}"
68
+
69
+
70
  @tool
71
  def get_current_time_in_timezone(timezone: str) -> str:
72
  """A tool that fetches the current local time in a specified timezone.
 
104
 
105
  agent = CodeAgent(
106
  model=model,
107
+ tools=[final_answer, get_current_time_in_timezone, get_weather_info], ## add your tools here (don't remove final answer)
108
  max_steps=6,
109
  verbosity_level=1,
110
  grammar=None,