|
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 |
|
""" |
|
|
|
|
|
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 |
|
|