CoolFace
Apppublic

Sanath-18/First_agent

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
customtools.py68 linesDownload Raw Back to root
1 2from smolagents import tool3 4@tool5def get_top_pokemon(x : int)->str:6    """Get the names of the top Pokémons as per the user.7    Args:8        x (int): Number of pokemon user wants to fetch.9 10    Returns:11        dict: A dictionary containing Pokémon name, ID, height, weight, types, abilities, and base stats.12    """13    import requests14    url = f"https://pokeapi.co/api/v2/pokemon?limit={x}"15    response = requests.get(url)16 17    if response.status_code == 200:18        data = response.json()19        pokemon_names = [pokemon['name'] for pokemon in data['results']]20        return pokemon_names21    else:22        print("Failed to fetch data:", response.status_code)23        return []24 25@tool26def get_pokemon_details(pokemon_name: str) -> dict:27    """28    Fetch detailed information about a specific Pokémon from the PokéAPI.29 30    Args:31        pokemon_name (str): The name of the Pokémon to fetch details for.32 33    Returns:34        dict: A dictionary containing Pokémon name, ID, height, weight, types, abilities, and base stats.35    """36    import requests37    url = f"https://pokeapi.co/api/v2/pokemon/{pokemon_name.lower()}"38    response = requests.get(url)39 40    if response.status_code == 200:41        data = response.json()42        return {43            "Name": data["name"].capitalize(),44            "ID": data["id"],45            "Height": data["height"],46            "Weight": data["weight"],47            "Types": [t["type"]["name"] for t in data["types"]],48            "Abilities": [a["ability"]["name"] for a in data["abilities"]],49            "Base Stats": {stat["stat"]["name"]: stat["base_stat"] for stat in data["stats"]}50        }51    else:52        return {"error": "Pokémon not found!"}53 54# Example usage55if __name__ == "__main__":56    pokemon_name = "charizard"  # you can change this to any valid name57    details = get_pokemon_details(pokemon_name)58 59    if details:60        print("\nPokémon Details:")61        for key, value in details.items():62            print(f"{key}: {value}")63    64    # Example usage65    top_20 = get_top_20_pokemon()66    print("Top 20 Pokémon:")67    for i, name in enumerate(top_20, 1):68        print(f"{i}. {name.capitalize()}")