Spaces:
Sleeping
Sleeping
moved api key out of code
Browse files- tools/weather.py +2 -1
tools/weather.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from smolagents.tools import Tool
|
| 2 |
import requests
|
| 3 |
from typing import Any, Optional
|
|
|
|
| 4 |
|
| 5 |
class WeatherTool(Tool):
|
| 6 |
"""Tool for getting weather information for a location."""
|
|
@@ -27,7 +28,7 @@ class WeatherTool(Tool):
|
|
| 27 |
"""
|
| 28 |
try:
|
| 29 |
# Using OpenWeatherMap API with a free tier (limited requests)
|
| 30 |
-
api_key =
|
| 31 |
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
|
| 32 |
|
| 33 |
response = requests.get(url)
|
|
|
|
| 1 |
from smolagents.tools import Tool
|
| 2 |
import requests
|
| 3 |
from typing import Any, Optional
|
| 4 |
+
import os # Added for accessing environment variables
|
| 5 |
|
| 6 |
class WeatherTool(Tool):
|
| 7 |
"""Tool for getting weather information for a location."""
|
|
|
|
| 28 |
"""
|
| 29 |
try:
|
| 30 |
# Using OpenWeatherMap API with a free tier (limited requests)
|
| 31 |
+
api_key = os.getenv('OPENWEATHERMAP_API_KEY') # OpenWeatherMap API key from env variable
|
| 32 |
url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric"
|
| 33 |
|
| 34 |
response = requests.get(url)
|