Update tools/get_pokemon_info.py
Browse filesRefactored for allowing code execution
tools/get_pokemon_info.py
CHANGED
|
@@ -6,7 +6,7 @@ import smolagents
|
|
| 6 |
import pokebase as pb
|
| 7 |
|
| 8 |
class GetPokemonInfoTool(Tool):
|
| 9 |
-
name = "
|
| 10 |
description = """"
|
| 11 |
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:
|
| 12 |
Name Description Type
|
|
@@ -35,20 +35,21 @@ class GetPokemonInfoTool(Tool):
|
|
| 35 |
inputs = {'name': {'type': 'string', 'description': 'The name of the pokemon.'}}
|
| 36 |
output_type = "object"
|
| 37 |
|
| 38 |
-
def
|
|
|
|
| 39 |
try:
|
| 40 |
import pokebase as pb
|
| 41 |
-
pokemon = pb.APIResource('pokemon', name)
|
| 42 |
except ImportError as e:
|
| 43 |
raise ImportError(
|
| 44 |
"You must install package `pokebase` to run this tool: for instance run `pip install pokebase`."
|
| 45 |
) from e
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except requests.exceptions.Timeout:
|
| 47 |
return "The request timed out. Please try again later."
|
| 48 |
except RequestException as e:
|
| 49 |
return "Error fetching contents from the pokemon remote API."
|
| 50 |
except Exception as e:
|
| 51 |
return f"An unexpected error occurred: {str(e)}"
|
| 52 |
-
|
| 53 |
-
def __init__(self, *args, **kwargs):
|
| 54 |
-
self.is_initialized = False
|
|
|
|
| 6 |
import pokebase as pb
|
| 7 |
|
| 8 |
class GetPokemonInfoTool(Tool):
|
| 9 |
+
name = "get_pokemon_info"
|
| 10 |
description = """"
|
| 11 |
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:
|
| 12 |
Name Description Type
|
|
|
|
| 35 |
inputs = {'name': {'type': 'string', 'description': 'The name of the pokemon.'}}
|
| 36 |
output_type = "object"
|
| 37 |
|
| 38 |
+
def __init__(self, *args, **kwargs):
|
| 39 |
+
super().__init__()
|
| 40 |
try:
|
| 41 |
import pokebase as pb
|
|
|
|
| 42 |
except ImportError as e:
|
| 43 |
raise ImportError(
|
| 44 |
"You must install package `pokebase` to run this tool: for instance run `pip install pokebase`."
|
| 45 |
) from e
|
| 46 |
+
|
| 47 |
+
def forward(self, name: str) -> object:
|
| 48 |
+
try:
|
| 49 |
+
pokemon = pb.APIResource('pokemon', name)
|
| 50 |
except requests.exceptions.Timeout:
|
| 51 |
return "The request timed out. Please try again later."
|
| 52 |
except RequestException as e:
|
| 53 |
return "Error fetching contents from the pokemon remote API."
|
| 54 |
except Exception as e:
|
| 55 |
return f"An unexpected error occurred: {str(e)}"
|
|
|
|
|
|
|
|
|