Parthjain9925 commited on
Commit
b0e52e1
·
verified ·
1 Parent(s): 0487437

pokeinformation returns moves and evolution chains

Browse files
Files changed (1) hide show
  1. app.py +55 -36
app.py CHANGED
@@ -5,6 +5,7 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import os
 
8
 
9
  from Gradio_UI import GradioUI
10
 
@@ -46,46 +47,64 @@ custom_role_conversions=None,
46
 
47
  @tool
48
  def get_pokemon_information(pokemon_name: str) -> dict:
49
- '''
50
  This tool gives information about a pokemon.
51
- The information given is
52
- Moves
53
- Abilities
54
- Types
55
- Pokémon Evolution Chains.
56
- base_experience
57
- stats
58
- weight
59
- height
60
- sprites-> image url of the pokemon could be shiny
 
 
61
  Use this tool to get the information about a pokemon else use the web search tool.
 
62
  Args:
63
  pokemon_name: The name of the pokemon.
64
- Returns: dict
65
- The information about the pokemon.
66
- '''
67
- try:
68
- response = requests.get(f"https://pokeapi.co/api/v2/pokemon/{pokemon_name}")
69
- response.raise_for_status()
70
- pokemon_info_json = response.json()
71
-
72
- pokemon_info = {
73
- "moves": pokemon_info_json["moves"],
74
- "abilities": pokemon_info_json["abilities"],
75
- "types": pokemon_info_json["types"],
76
- "evolution_chains": pokemon_info_json["evolution_chain"],
77
- "base_experience": pokemon_info_json["base_experience"],
78
- "stats": pokemon_info_json["stats"],
79
- "weight": pokemon_info_json["weight"],
80
- "height": pokemon_info_json["height"],
81
- "sprites": pokemon_info_json["sprites"],
82
- "pokedex_number": pokemon_info_json["id"],
83
- "location_area_url": pokemon_info_json["location_area_encounters"]
84
- }
85
- except requests.exceptions.RequestException as e:
86
- return f"Error fetching the Pokemon number: {str(e)}"
87
- except Exception as e:
88
- return f"An unexpected error occurred: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  return pokemon_info
90
 
91
  web_search_tool = DuckDuckGoSearchTool()
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import os
8
+ import pokebase as pb
9
 
10
  from Gradio_UI import GradioUI
11
 
 
47
 
48
  @tool
49
  def get_pokemon_information(pokemon_name: str) -> dict:
50
+ """
51
  This tool gives information about a pokemon.
52
+ Just pass the name of the pokemon as an argument in the string format.
53
+
54
+ The information given is:
55
+ - Moves
56
+ - Abilities
57
+ - Types
58
+ - Pokémon Evolution Chains
59
+ - base_experience
60
+ - stats
61
+ - weight
62
+ - height
63
+
64
  Use this tool to get the information about a pokemon else use the web search tool.
65
+
66
  Args:
67
  pokemon_name: The name of the pokemon.
68
+
69
+ Returns:
70
+ dict: A dictionary conaining The information about the pokemon like moves, abilities, types, evolution chains, base experience, stats, weight, height, sprites
71
+ """
72
+ if type(pokemon_name) != str:
73
+ return "Please pass the pokemon name as a string"
74
+
75
+ client = pb
76
+ pokemon = client.pokemon(pokemon_name)
77
+ if pokemon is None:
78
+ return "Please pass a valid pokemon name"
79
+
80
+
81
+ evolution_number = client.pokemon_species(pokemon_name).evolution_chain.id
82
+ e_chain = client.evolution_chain(evolution_number).chain
83
+
84
+
85
+ e2 = "none"
86
+ e3 = "none"
87
+ e1 = e_chain.species.name
88
+ if len(e_chain.evolves_to)>0:
89
+ e2 = e_chain.evolves_to[0].species.name
90
+ if len(e_chain.evolves_to[0].evolves_to)>0:
91
+ e3 = e_chain.evolves_to[0].evolves_to[0].species.name
92
+
93
+ chain_str = f"Evolution chain is: {e1} -> {e2} -> {e3}"
94
+
95
+
96
+ pokemon_info = {
97
+ "moves": str([move.name for move in pb.move(pokemon_name).results]),
98
+ "types": str([type.type.name for type in pokemon.types]),
99
+ "stats": str({ stats.stat.name: pokemon.stats[i].base_stat for i, stats in enumerate(pokemon.stats)}),
100
+ "expierience": pokemon.base_experience,
101
+ "species": pokemon.species,
102
+ "weight": pokemon.weight,
103
+ "height": pokemon.height,
104
+ "abilities": str([ability.ability for ability in pokemon.abilities]),
105
+ "evolution_chain": chain_str
106
+ }
107
+
108
  return pokemon_info
109
 
110
  web_search_tool = DuckDuckGoSearchTool()