Spaces:
Sleeping
Sleeping
add pokemon tools
Browse files
app.py
CHANGED
|
@@ -139,6 +139,73 @@ def search_wikipedia(query: str) -> str:
|
|
| 139 |
except requests.exceptions.RequestException as e:
|
| 140 |
return f"Error fetching Wikipedia data: {str(e)}"
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
search_tool = DuckDuckGoSearchTool()
|
| 143 |
|
| 144 |
final_answer = FinalAnswerTool()
|
|
@@ -147,7 +214,7 @@ final_answer = FinalAnswerTool()
|
|
| 147 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 148 |
|
| 149 |
model = HfApiModel(
|
| 150 |
-
max_tokens=
|
| 151 |
temperature=0.5,
|
| 152 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 153 |
custom_role_conversions=None,
|
|
@@ -171,7 +238,9 @@ agent = CodeAgent(
|
|
| 171 |
get_joke,
|
| 172 |
get_time_in_timezone,
|
| 173 |
get_random_fact,
|
| 174 |
-
search_wikipedia
|
|
|
|
|
|
|
| 175 |
], ## add your tools here (don't remove final answer)
|
| 176 |
max_steps=6,
|
| 177 |
verbosity_level=1,
|
|
|
|
| 139 |
except requests.exceptions.RequestException as e:
|
| 140 |
return f"Error fetching Wikipedia data: {str(e)}"
|
| 141 |
|
| 142 |
+
@tool
|
| 143 |
+
def get_pokemon_data(pokemon_name: str) -> dict:
|
| 144 |
+
"""Fetches a summarized version of Pokémon data from the PokéAPI.
|
| 145 |
+
|
| 146 |
+
Args:
|
| 147 |
+
pokemon_name: The name of the Pokémon (case insensitive).
|
| 148 |
+
|
| 149 |
+
Returns:
|
| 150 |
+
A dictionary with relevant Pokémon information: name, ID, types, abilities, height, weight, and sprite.
|
| 151 |
+
"""
|
| 152 |
+
try:
|
| 153 |
+
pokemon_name = pokemon_name.lower()
|
| 154 |
+
response = requests.get(f"https://pokeapi.co/api/v2/pokemon/{pokemon_name}")
|
| 155 |
+
|
| 156 |
+
if response.status_code != 200:
|
| 157 |
+
return {"error": f"Pokémon '{pokemon_name}' not found."}
|
| 158 |
+
|
| 159 |
+
data = response.json()
|
| 160 |
+
|
| 161 |
+
# Extract relevant information
|
| 162 |
+
return {
|
| 163 |
+
"name": data["name"].capitalize(),
|
| 164 |
+
"id": data["id"],
|
| 165 |
+
"types": [t["type"]["name"].capitalize() for t in data["types"]],
|
| 166 |
+
"abilities": [a["ability"]["name"].replace("-", " ").capitalize() for a in data["abilities"]],
|
| 167 |
+
"height": data["height"] / 10, # Convert from decimeters to meters
|
| 168 |
+
"weight": data["weight"] / 10, # Convert from hectograms to kilograms
|
| 169 |
+
"sprite": data["sprites"]["front_default"] # URL of Pokémon image
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
except Exception as e:
|
| 173 |
+
return {"error": f"Failed to retrieve Pokémon data: {e}"}
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
@tool
|
| 177 |
+
def get_pokemon_move(move_name: str) -> dict:
|
| 178 |
+
"""Fetches a summarized version of Pokémon move data from the PokéAPI.
|
| 179 |
+
|
| 180 |
+
Args:
|
| 181 |
+
move_name: The name of the move (case insensitive).
|
| 182 |
+
|
| 183 |
+
Returns:
|
| 184 |
+
A dictionary with relevant move information: name, power, accuracy, PP, type, and effect.
|
| 185 |
+
"""
|
| 186 |
+
try:
|
| 187 |
+
move_name = move_name.lower().replace(" ", "-")
|
| 188 |
+
response = requests.get(f"https://pokeapi.co/api/v2/move/{move_name}")
|
| 189 |
+
|
| 190 |
+
if response.status_code != 200:
|
| 191 |
+
return {"error": f"Move '{move_name}' not found."}
|
| 192 |
+
|
| 193 |
+
data = response.json()
|
| 194 |
+
|
| 195 |
+
# Extract relevant information
|
| 196 |
+
return {
|
| 197 |
+
"name": data["name"].capitalize(),
|
| 198 |
+
"power": data.get("power", "N/A"), # Some moves have no power
|
| 199 |
+
"accuracy": data.get("accuracy", "N/A"), # Some moves have no accuracy
|
| 200 |
+
"pp": data["pp"],
|
| 201 |
+
"type": data["type"]["name"].capitalize(),
|
| 202 |
+
"effect": data["effect_entries"][0]["short_effect"] if data["effect_entries"] else "No effect description available."
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
except Exception as e:
|
| 206 |
+
return {"error": f"Failed to retrieve move data: {e}"}
|
| 207 |
+
|
| 208 |
+
|
| 209 |
search_tool = DuckDuckGoSearchTool()
|
| 210 |
|
| 211 |
final_answer = FinalAnswerTool()
|
|
|
|
| 214 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 215 |
|
| 216 |
model = HfApiModel(
|
| 217 |
+
max_tokens=5024,
|
| 218 |
temperature=0.5,
|
| 219 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 220 |
custom_role_conversions=None,
|
|
|
|
| 238 |
get_joke,
|
| 239 |
get_time_in_timezone,
|
| 240 |
get_random_fact,
|
| 241 |
+
search_wikipedia,
|
| 242 |
+
get_pokemon_data,
|
| 243 |
+
get_pokemon_move,
|
| 244 |
], ## add your tools here (don't remove final answer)
|
| 245 |
max_steps=6,
|
| 246 |
verbosity_level=1,
|