First_agent_template / tools /get_weather.py
Negrec23's picture
Rename tools/get_weather to tools/get_weather.py
7a6a4f8 verified
Raw History Blame Contribute Delete
547 Bytes
@tool
def get_weather(city: str) -> str:
"""Fetches the current weather for a specified city.
Args:
city: The name of the city to fetch the weather for.
"""
api_url = f"http://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q={city}"
response = requests.get(api_url)
if response.status_code == 200:
data = response.json()
return f"The weather in {city} is {data['current']['temp_c']}°C with {data['current']['condition']['text']}."
else:
return "Failed to fetch weather data."