EmincanY commited on
Commit
90a7341
·
verified ·
1 Parent(s): 49cd06a

Upload 3 files

Browse files
tools/time_tool.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ import datetime
3
+ import pytz
4
+
5
+ @tool
6
+ def get_current_time_in_timezone(timezone: str) -> str:
7
+ """A tool that fetches the current local time in a specified timezone.
8
+ Args:
9
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
10
+ """
11
+ try:
12
+ # Create timezone object
13
+ tz = pytz.timezone(timezone)
14
+ # Get current time in that timezone
15
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
16
+ return f"The current local time in {timezone} is: {local_time}"
17
+ except Exception as e:
18
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
tools/weather_tool.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ import os
3
+ import requests
4
+
5
+ @tool
6
+ def get_weather(city: str) -> str:
7
+ """Get current weather information for a specified city
8
+ Args:
9
+ city: Name of the city to get weather for
10
+ """
11
+ # Using OpenWeatherMap API
12
+ API_KEY = os.getenv("OPENWEATHERMAP_API_KEY")
13
+ if not API_KEY:
14
+ return "Error: OpenWeatherMap API key not found in environment variables"
15
+
16
+ base_url = "http://api.openweathermap.org/data/2.5/weather"
17
+
18
+ try:
19
+ params = {
20
+ 'q': city,
21
+ 'appid': API_KEY,
22
+ 'units': 'metric' # For Celsius
23
+ }
24
+ response = requests.get(base_url, params=params)
25
+ data = response.json()
26
+
27
+ if response.status_code == 200:
28
+ temp = data['main']['temp']
29
+ humidity = data['main']['humidity']
30
+ description = data['weather'][0]['description']
31
+ return f"Weather in {city}: Temperature: {temp}°C, Humidity: {humidity}%, Conditions: {description}"
32
+ else:
33
+ return f"Error getting weather: {data.get('message', 'Unknown error')}"
34
+ except Exception as e:
35
+ return f"Error: {str(e)}"
tools/wikipedia_tool.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ import wikipediaapi
3
+
4
+ @tool
5
+ def get_wikipedia_summary(topic: str) -> str:
6
+ """Get a summary of a Wikipedia article
7
+ Args:
8
+ topic: Topic to get summary for
9
+ """
10
+ wiki = wikipediaapi.Wikipedia(
11
+ user_agent='HuggingFaceAgent/1.0 (https://huggingface.co/; contact@huggingface.co)',
12
+ language='en'
13
+ )
14
+ try:
15
+ page = wiki.page(topic)
16
+ if page.exists():
17
+ # Get first two sentences or first 500 characters, whichever is shorter
18
+ summary = page.summary[:500]
19
+ if len(summary) == 500:
20
+ summary = summary[:summary.rindex('.')] + '.'
21
+ return summary
22
+ return f"No Wikipedia article found for: {topic}"
23
+ except Exception as e:
24
+ return f"Error fetching Wikipedia summary: {str(e)}"