File size: 3,330 Bytes
2259bc6
 
 
 
 
 
 
 
6bc3785
e0dcf1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2259bc6
ff9510b
2259bc6
6bc3785
 
2259bc6
 
 
 
 
 
6bc3785
 
 
 
ff9510b
 
 
 
 
 
0ff14e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from typing import Any, Optional
from smolagents.tools import Tool
import requests
import markdownify
import smolagents
import pokebase as pb

class GetPokemonInfoTool(Tool):
    name = "get_pokemon_info"
    description = """"
        Retrieves complete information on a given Pokemon. Use this to get information for a pokemon. It will return a python object where you can then find the following object properties, eacho one is described as name, description and type:
        Name	Description	Type
        id	The identifier for this resource.	integer
        name	The name for this resource.	string
        base_experience	The base experience gained for defeating this Pokémon.	integer
        height	The height of this Pokémon in decimetres.	integer
        is_default	Set for exactly one Pokémon used as the default for each species.	boolean
        order	Order for sorting. Almost national order, except families are grouped together.	integer
        weight	The weight of this Pokémon in hectograms.	integer
        abilities	A list of abilities this Pokémon could potentially have.	list PokemonAbility
        forms	A list of forms this Pokémon can take on.	list NamedAPIResource (PokemonForm)
        game_indices	A list of game indices relevent to Pokémon item by generation.	list VersionGameIndex
        held_items	A list of items this Pokémon may be holding when encountered.	list PokemonHeldItem
        location_area_encounters	A link to a list of location areas, as well as encounter details pertaining to specific versions.	string
        moves	A list of moves along with learn methods and level details pertaining to specific version groups.	list PokemonMove
        past_types	A list of details showing types this pokémon had in previous generations	list PokemonTypePast
        sprites	A set of sprites used to depict this Pokémon in the game. A visual representation of the various sprites can be found at PokeAPI/sprites	PokemonSprites
        cries	A set of cries used to depict this Pokémon in the game. A visual representation of the various cries can be found at PokeAPI/cries	PokemonCries
        species	The species this Pokémon belongs to.	NamedAPIResource (PokemonSpecies)
        stats	A list of base stat values for this Pokémon.	list PokemonStat
        types	A list of details showing types this Pokémon has.	list PokemonType
    """
    #All info gathered from pokeapi v2 official documentation
    
    inputs = {'name': {'type': 'string', 'description': 'The name of the pokemon.'}}
    output_type = "object"

    def __init__(self, *args, **kwargs):
        super().__init__()
        try:
            import pokebase as pb
        except ImportError as e:
            raise ImportError(
                "You must install package `pokebase` to run this tool: for instance run `pip install pokebase`."
            ) from e
    
    def forward(self, name: str) -> object:
        try:
            pokemon = pb.APIResource('pokemon', name)
        except requests.exceptions.Timeout:
            return "The request timed out. Please try again later."
        except RequestException as e:
            return "Error fetching contents from the pokemon remote API."
        except Exception as e:
            return f"An unexpected error occurred: {str(e)}"
        return pokemon