File size: 898 Bytes
2acf84f
3fcf7a5
2acf84f
 
3fcf7a5
2acf84f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from urllib.parse import quote

import requests
from smolagents import tool


@tool
def get_weather(location: str) -> str:
    """Fetches the current live weather report and temperature for a given city or location.

    Args:
        location: The name of the city or location (e.g., 'Paris', 'Tokyo', 'San Francisco').
    """
    try:
        encoded_loc = quote(location)
        url = f"https://wttr.in/{encoded_loc}?format=%C+%t+(feels+like+%f)+wind:+%w"
        headers = {"User-Agent": "HF-Agents-Course-ArkAssistant/1.0"}
        resp = requests.get(url, headers=headers, timeout=10)
        if resp.status_code == 200 and resp.text:
            return f"Weather for {location}: {resp.text.strip()}"
        return f"Could not retrieve weather for {location} (status code {resp.status_code})."
    except Exception as e:
        return f"Error fetching weather for '{location}': {str(e)}"