harisali commited on
Commit
2af39fa
·
1 Parent(s): a6e692e

final push

Browse files
Files changed (3) hide show
  1. app.py +321 -54
  2. prompts.yaml +326 -321
  3. requirements.txt +5 -2
app.py CHANGED
@@ -1,19 +1,21 @@
1
- from smolagents import CodeAgent, tool, OpenAIServerModel
 
2
  import requests
3
  import yaml
4
  import os
5
  from collections import defaultdict
6
  from tools.final_answer import FinalAnswerTool
7
- from Gradio_UI import GradioUI
 
8
 
9
  @tool
10
  def get_pokedex_entry(pokemon_name: str) -> str:
11
  """
12
  Fetches the English Pokédex entry (flavor text) for the given Pokémon.
13
-
14
  Args:
15
  pokemon_name: Name or ID of the Pokémon (e.g., 'pikachu').
16
-
17
  Returns:
18
  A string containing the Pokémon's English Pokédex entry or an error message.
19
  """
@@ -34,14 +36,15 @@ def get_pokedex_entry(pokemon_name: str) -> str:
34
  title = pokemon_name.strip().title()
35
  return f"{title}: {entry}"
36
 
 
37
  @tool
38
  def get_pokemon_basic_info(pokemon_name: str) -> str:
39
  """
40
  Fetches basic information about a Pokémon, such as its ID, height, weight, and types.
41
-
42
  Args:
43
  pokemon_name: The name or ID of the Pokémon (e.g., 'pikachu').
44
-
45
  Returns:
46
  A string summarizing the Pokémon's ID, height, weight, and types, or an error message.
47
  """
@@ -58,14 +61,15 @@ def get_pokemon_basic_info(pokemon_name: str) -> str:
58
  f"Types: {types}"
59
  )
60
 
 
61
  @tool
62
  def get_pokemon_abilities(pokemon_name: str) -> str:
63
  """
64
  Retrieves a list of abilities for a given Pokémon, distinguishing between normal and hidden abilities.
65
-
66
  Args:
67
  pokemon_name: The name or ID of the Pokémon.
68
-
69
  Returns:
70
  A string listing the Pokémon's abilities, labeled as Normal or Hidden, or an error message.
71
  """
@@ -84,14 +88,15 @@ def get_pokemon_abilities(pokemon_name: str) -> str:
84
  return f"No abilities found for '{pokemon_name}'."
85
  return f"{pokemon_name.title()}'s abilities:\n" + "\n".join(abilities)
86
 
 
87
  @tool
88
  def get_pokemon_base_stats(pokemon_name: str) -> str:
89
  """
90
  Fetches the base stats (HP, Attack, Defense, etc.) of a Pokémon.
91
-
92
  Args:
93
  pokemon_name: The name or ID of the Pokémon.
94
-
95
  Returns:
96
  A string summarizing the Pokémon's base stats or an error message.
97
  """
@@ -107,14 +112,15 @@ def get_pokemon_base_stats(pokemon_name: str) -> str:
107
  stats_str = ', '.join([f"{k}: {v}" for k, v in stats.items()])
108
  return f"{pokemon_name.title()}'s base stats: {stats_str}"
109
 
 
110
  @tool
111
  def get_pokemon_evolutions(pokemon_name: str) -> str:
112
  """
113
  Retrieves the evolution chain for a given Pokémon.
114
-
115
  Args:
116
  pokemon_name: The name or ID of the Pokémon.
117
-
118
  Returns:
119
  A string listing the evolution chain or an error message.
120
  """
@@ -130,23 +136,26 @@ def get_pokemon_evolutions(pokemon_name: str) -> str:
130
  if evo_response.status_code != 200:
131
  return f"Error fetching evolution chain (HTTP {evo_response.status_code})."
132
  evo_data = evo_response.json()
 
133
  def extract_chain(chain):
134
  names = [chain['species']['name'].title()]
135
  for evo in chain.get('evolves_to', []):
136
  names.extend(extract_chain(evo))
137
  return names
 
138
  evo_names = extract_chain(evo_data['chain'])
139
  return f"Evolution chain: {' → '.join(evo_names)}"
140
 
 
141
  @tool
142
  def get_pokemon_moves_grouped(pokemon_name: str) -> str:
143
  """
144
  Lists all moves a Pokémon can learn, grouped by move name, showing the minimum level,
145
  all learning methods, and all game versions. Egg moves are listed separately.
146
-
147
  Args:
148
  pokemon_name: The name or ID of the Pokémon.
149
-
150
  Returns:
151
  A string listing the Pokémon's moves, grouped by name, with levels, methods, and versions.
152
  """
@@ -169,7 +178,8 @@ def get_pokemon_moves_grouped(pokemon_name: str) -> str:
169
  else:
170
  moves_dict[move_name]['methods'].add(method)
171
  moves_dict[move_name]['versions'].add(version)
172
- if method == "Level Up" and (moves_dict[move_name]['level'] is None or level < moves_dict[move_name]['level']):
 
173
  moves_dict[move_name]['level'] = level
174
  moves_lines = []
175
  for move_name, info in sorted(moves_dict.items()):
@@ -179,9 +189,10 @@ def get_pokemon_moves_grouped(pokemon_name: str) -> str:
179
  moves_lines.append(f"{move_name} (Level {info['level']}, Versions: {versions_str})")
180
  else:
181
  moves_lines.append(f"{move_name} (Methods: {methods_str}, Versions: {versions_str})")
182
- egg_lines = [f"{move_name} (Egg Move in: {', '.join(sorted(versions))})" for move_name, versions in sorted(egg_moves_dict.items())]
 
183
  moves_preview = '\n'.join(moves_lines[:20])
184
- more_moves = f"\n...and {len(moves_lines)-20} more moves." if len(moves_lines) > 20 else ""
185
  egg_moves_output = '\n'.join(egg_lines) if egg_lines else 'None'
186
  return (
187
  f"{pokemon_name.title()} can learn these moves grouped by name with versions and levels:\n"
@@ -189,14 +200,15 @@ def get_pokemon_moves_grouped(pokemon_name: str) -> str:
189
  f"Egg moves:\n{egg_moves_output}"
190
  )
191
 
 
192
  @tool
193
  def get_pokemon_sprite(pokemon_name: str) -> str:
194
  """
195
  Fetches the default front sprite URL for a Pokémon.
196
-
197
  Args:
198
  pokemon_name: The name or ID of the Pokémon.
199
-
200
  Returns:
201
  A string containing the sprite URL or an error message.
202
  """
@@ -211,14 +223,15 @@ def get_pokemon_sprite(pokemon_name: str) -> str:
211
  return f"No sprite found for '{pokemon_name}'."
212
  return f"{pokemon_name.title()} sprite: {sprite_url}"
213
 
 
214
  @tool
215
  def get_pokemon_held_items(pokemon_name: str) -> str:
216
  """
217
  Fetches the items a Pokémon can hold in the wild, including rarity and game versions.
218
-
219
  Args:
220
  pokemon_name: The name or ID of the Pokémon.
221
-
222
  Returns:
223
  A string listing the Pokémon's held items, their rarity, and versions, or an error message.
224
  """
@@ -239,14 +252,15 @@ def get_pokemon_held_items(pokemon_name: str) -> str:
239
  item_lines.append(f"{item_name} (Rarity: {rarity}%, Versions: {versions})")
240
  return f"{pokemon_name.title()}'s held items:\n" + "\n".join(item_lines)
241
 
 
242
  @tool
243
  def get_pokemon_encounter_locations(pokemon_name: str) -> str:
244
  """
245
  Fetches the locations where a Pokémon can be encountered in different game versions.
246
-
247
  Args:
248
  pokemon_name: The name or ID of the Pokémon.
249
-
250
  Returns:
251
  A string listing the Pokémon's encounter locations by game version, or an error message.
252
  """
@@ -277,14 +291,15 @@ def get_pokemon_encounter_locations(pokemon_name: str) -> str:
277
  return f"No encounter locations found for '{pokemon_name}'."
278
  return f"{pokemon_name.title()}'s encounter locations:\n" + "\n".join(output)
279
 
 
280
  @tool
281
  def get_pokemon_type_effectiveness(pokemon_name: str) -> str:
282
  """
283
  Fetches the type effectiveness (weaknesses, resistances, immunities) for a Pokémon's types.
284
-
285
  Args:
286
  pokemon_name: The name or ID of the Pokémon.
287
-
288
  Returns:
289
  A string summarizing the Pokémon's type effectiveness, or an error message.
290
  """
@@ -316,14 +331,15 @@ def get_pokemon_type_effectiveness(pokemon_name: str) -> str:
316
  return f"No type effectiveness data found for '{pokemon_name}'."
317
  return f"{pokemon_name.title()}'s type effectiveness:\n" + "\n".join(output)
318
 
 
319
  @tool
320
  def get_pokemon_ability_description(pokemon_name: str) -> str:
321
  """
322
  Fetches the descriptions of a Pokémon's abilities from the ability endpoint.
323
-
324
  Args:
325
  pokemon_name: The name or ID of the Pokémon.
326
-
327
  Returns:
328
  A string listing each ability and its English description, or an error message.
329
  """
@@ -343,21 +359,23 @@ def get_pokemon_ability_description(pokemon_name: str) -> str:
343
  if response.status_code != 200:
344
  continue
345
  ability_data = response.json()
346
- effect = next((e['effect'] for e in ability_data['effect_entries'] if e['language']['name'] == 'en'), 'No description available.')
 
347
  output.append(f"{ability_name} ({label}): {effect}")
348
  if not output:
349
  return f"No ability descriptions found for '{pokemon_name}'."
350
  return f"{pokemon_name.title()}'s ability descriptions:\n" + "\n".join(output)
351
 
 
352
  @tool
353
  def list_pokemon_by_type(type_name: str, limit: int = 10) -> str:
354
  """
355
  Lists Pokémon that have a specific type, up to a specified limit.
356
-
357
  Args:
358
  type_name: The name of the type (e.g., 'normal').
359
  limit: Maximum number of Pokémon to list (default: 10).
360
-
361
  Returns:
362
  A string listing Pokémon with the specified type, or an error message.
363
  """
@@ -372,42 +390,241 @@ def list_pokemon_by_type(type_name: str, limit: int = 10) -> str:
372
  return f"No Pokémon found with type '{type_name}'."
373
  return f"Pokémon with {type_name.title()} type (up to {limit}):\n" + "\n".join(pokemon_list)
374
 
 
375
  @tool
376
  def get_pokemon_full_profile(pokemon_name: str) -> str:
377
  """
378
  Fetches a complete profile for a Pokémon, including all available data.
379
-
380
  Args:
381
  pokemon_name: The name or ID of the Pokémon.
382
-
383
  Returns:
384
  A string with a comprehensive Pokémon profile.
385
  """
386
  name = pokemon_name.strip().lower()
387
- profile = []
388
- profile.append(get_pokedex_entry(pokemon_name=name))
389
- profile.append(get_pokemon_basic_info(pokemon_name=name))
390
- profile.append(get_pokemon_abilities(pokemon_name=name))
391
- profile.append(get_pokemon_base_stats(pokemon_name=name))
392
- profile.append(get_pokemon_evolutions(pokemon_name=name))
393
- profile.append(get_pokemon_moves_grouped(pokemon_name=name))
394
- profile.append(get_pokemon_held_items(pokemon_name=name))
395
- profile.append(get_pokemon_encounter_locations(pokemon_name=name))
396
- profile.append(get_pokemon_type_effectiveness(pokemon_name=name))
397
- profile.append(get_pokemon_ability_description(pokemon_name=name))
398
- profile.append(get_pokemon_sprite(pokemon_name=name))
 
399
  return f"{name.title()} Profile:\n\n" + "\n\n".join(profile)
400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  final_answer = FinalAnswerTool()
402
 
403
- model = OpenAIServerModel(
404
- model_id="meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
405
- api_base="https://api.together.xyz/v1/",
406
- api_key=os.environ["TOGETHER_API_KEY"],
407
  )
408
 
409
- with open("prompts.yaml", 'r') as stream:
410
- prompt_templates = yaml.safe_load(stream)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
 
412
  agent = CodeAgent(
413
  model=model,
@@ -425,11 +642,61 @@ agent = CodeAgent(
425
  get_pokemon_type_effectiveness,
426
  get_pokemon_ability_description,
427
  list_pokemon_by_type,
428
- get_pokemon_full_profile
 
 
429
  ],
430
- max_steps=6,
431
  verbosity_level=2,
432
- prompt_templates=prompt_templates
433
  )
434
 
435
- GradioUI(agent).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from smolagents import CodeAgent, tool, LiteLLMModel
3
  import requests
4
  import yaml
5
  import os
6
  from collections import defaultdict
7
  from tools.final_answer import FinalAnswerTool
8
+ import gradio as gr
9
+
10
 
11
  @tool
12
  def get_pokedex_entry(pokemon_name: str) -> str:
13
  """
14
  Fetches the English Pokédex entry (flavor text) for the given Pokémon.
15
+
16
  Args:
17
  pokemon_name: Name or ID of the Pokémon (e.g., 'pikachu').
18
+
19
  Returns:
20
  A string containing the Pokémon's English Pokédex entry or an error message.
21
  """
 
36
  title = pokemon_name.strip().title()
37
  return f"{title}: {entry}"
38
 
39
+
40
  @tool
41
  def get_pokemon_basic_info(pokemon_name: str) -> str:
42
  """
43
  Fetches basic information about a Pokémon, such as its ID, height, weight, and types.
44
+
45
  Args:
46
  pokemon_name: The name or ID of the Pokémon (e.g., 'pikachu').
47
+
48
  Returns:
49
  A string summarizing the Pokémon's ID, height, weight, and types, or an error message.
50
  """
 
61
  f"Types: {types}"
62
  )
63
 
64
+
65
  @tool
66
  def get_pokemon_abilities(pokemon_name: str) -> str:
67
  """
68
  Retrieves a list of abilities for a given Pokémon, distinguishing between normal and hidden abilities.
69
+
70
  Args:
71
  pokemon_name: The name or ID of the Pokémon.
72
+
73
  Returns:
74
  A string listing the Pokémon's abilities, labeled as Normal or Hidden, or an error message.
75
  """
 
88
  return f"No abilities found for '{pokemon_name}'."
89
  return f"{pokemon_name.title()}'s abilities:\n" + "\n".join(abilities)
90
 
91
+
92
  @tool
93
  def get_pokemon_base_stats(pokemon_name: str) -> str:
94
  """
95
  Fetches the base stats (HP, Attack, Defense, etc.) of a Pokémon.
96
+
97
  Args:
98
  pokemon_name: The name or ID of the Pokémon.
99
+
100
  Returns:
101
  A string summarizing the Pokémon's base stats or an error message.
102
  """
 
112
  stats_str = ', '.join([f"{k}: {v}" for k, v in stats.items()])
113
  return f"{pokemon_name.title()}'s base stats: {stats_str}"
114
 
115
+
116
  @tool
117
  def get_pokemon_evolutions(pokemon_name: str) -> str:
118
  """
119
  Retrieves the evolution chain for a given Pokémon.
120
+
121
  Args:
122
  pokemon_name: The name or ID of the Pokémon.
123
+
124
  Returns:
125
  A string listing the evolution chain or an error message.
126
  """
 
136
  if evo_response.status_code != 200:
137
  return f"Error fetching evolution chain (HTTP {evo_response.status_code})."
138
  evo_data = evo_response.json()
139
+
140
  def extract_chain(chain):
141
  names = [chain['species']['name'].title()]
142
  for evo in chain.get('evolves_to', []):
143
  names.extend(extract_chain(evo))
144
  return names
145
+
146
  evo_names = extract_chain(evo_data['chain'])
147
  return f"Evolution chain: {' → '.join(evo_names)}"
148
 
149
+
150
  @tool
151
  def get_pokemon_moves_grouped(pokemon_name: str) -> str:
152
  """
153
  Lists all moves a Pokémon can learn, grouped by move name, showing the minimum level,
154
  all learning methods, and all game versions. Egg moves are listed separately.
155
+
156
  Args:
157
  pokemon_name: The name or ID of the Pokémon.
158
+
159
  Returns:
160
  A string listing the Pokémon's moves, grouped by name, with levels, methods, and versions.
161
  """
 
178
  else:
179
  moves_dict[move_name]['methods'].add(method)
180
  moves_dict[move_name]['versions'].add(version)
181
+ if method == "Level Up" and (
182
+ moves_dict[move_name]['level'] is None or level < moves_dict[move_name]['level']):
183
  moves_dict[move_name]['level'] = level
184
  moves_lines = []
185
  for move_name, info in sorted(moves_dict.items()):
 
189
  moves_lines.append(f"{move_name} (Level {info['level']}, Versions: {versions_str})")
190
  else:
191
  moves_lines.append(f"{move_name} (Methods: {methods_str}, Versions: {versions_str})")
192
+ egg_lines = [f"{move_name} (Egg Move in: {', '.join(sorted(versions))})" for move_name, versions in
193
+ sorted(egg_moves_dict.items())]
194
  moves_preview = '\n'.join(moves_lines[:20])
195
+ more_moves = f"\n...and {len(moves_lines) - 20} more moves." if len(moves_lines) > 20 else ""
196
  egg_moves_output = '\n'.join(egg_lines) if egg_lines else 'None'
197
  return (
198
  f"{pokemon_name.title()} can learn these moves grouped by name with versions and levels:\n"
 
200
  f"Egg moves:\n{egg_moves_output}"
201
  )
202
 
203
+
204
  @tool
205
  def get_pokemon_sprite(pokemon_name: str) -> str:
206
  """
207
  Fetches the default front sprite URL for a Pokémon.
208
+
209
  Args:
210
  pokemon_name: The name or ID of the Pokémon.
211
+
212
  Returns:
213
  A string containing the sprite URL or an error message.
214
  """
 
223
  return f"No sprite found for '{pokemon_name}'."
224
  return f"{pokemon_name.title()} sprite: {sprite_url}"
225
 
226
+
227
  @tool
228
  def get_pokemon_held_items(pokemon_name: str) -> str:
229
  """
230
  Fetches the items a Pokémon can hold in the wild, including rarity and game versions.
231
+
232
  Args:
233
  pokemon_name: The name or ID of the Pokémon.
234
+
235
  Returns:
236
  A string listing the Pokémon's held items, their rarity, and versions, or an error message.
237
  """
 
252
  item_lines.append(f"{item_name} (Rarity: {rarity}%, Versions: {versions})")
253
  return f"{pokemon_name.title()}'s held items:\n" + "\n".join(item_lines)
254
 
255
+
256
  @tool
257
  def get_pokemon_encounter_locations(pokemon_name: str) -> str:
258
  """
259
  Fetches the locations where a Pokémon can be encountered in different game versions.
260
+
261
  Args:
262
  pokemon_name: The name or ID of the Pokémon.
263
+
264
  Returns:
265
  A string listing the Pokémon's encounter locations by game version, or an error message.
266
  """
 
291
  return f"No encounter locations found for '{pokemon_name}'."
292
  return f"{pokemon_name.title()}'s encounter locations:\n" + "\n".join(output)
293
 
294
+
295
  @tool
296
  def get_pokemon_type_effectiveness(pokemon_name: str) -> str:
297
  """
298
  Fetches the type effectiveness (weaknesses, resistances, immunities) for a Pokémon's types.
299
+
300
  Args:
301
  pokemon_name: The name or ID of the Pokémon.
302
+
303
  Returns:
304
  A string summarizing the Pokémon's type effectiveness, or an error message.
305
  """
 
331
  return f"No type effectiveness data found for '{pokemon_name}'."
332
  return f"{pokemon_name.title()}'s type effectiveness:\n" + "\n".join(output)
333
 
334
+
335
  @tool
336
  def get_pokemon_ability_description(pokemon_name: str) -> str:
337
  """
338
  Fetches the descriptions of a Pokémon's abilities from the ability endpoint.
339
+
340
  Args:
341
  pokemon_name: The name or ID of the Pokémon.
342
+
343
  Returns:
344
  A string listing each ability and its English description, or an error message.
345
  """
 
359
  if response.status_code != 200:
360
  continue
361
  ability_data = response.json()
362
+ effect = next((e['effect'] for e in ability_data['effect_entries'] if e['language']['name'] == 'en'),
363
+ 'No description available.')
364
  output.append(f"{ability_name} ({label}): {effect}")
365
  if not output:
366
  return f"No ability descriptions found for '{pokemon_name}'."
367
  return f"{pokemon_name.title()}'s ability descriptions:\n" + "\n".join(output)
368
 
369
+
370
  @tool
371
  def list_pokemon_by_type(type_name: str, limit: int = 10) -> str:
372
  """
373
  Lists Pokémon that have a specific type, up to a specified limit.
374
+
375
  Args:
376
  type_name: The name of the type (e.g., 'normal').
377
  limit: Maximum number of Pokémon to list (default: 10).
378
+
379
  Returns:
380
  A string listing Pokémon with the specified type, or an error message.
381
  """
 
390
  return f"No Pokémon found with type '{type_name}'."
391
  return f"Pokémon with {type_name.title()} type (up to {limit}):\n" + "\n".join(pokemon_list)
392
 
393
+
394
  @tool
395
  def get_pokemon_full_profile(pokemon_name: str) -> str:
396
  """
397
  Fetches a complete profile for a Pokémon, including all available data.
398
+
399
  Args:
400
  pokemon_name: The name or ID of the Pokémon.
401
+
402
  Returns:
403
  A string with a comprehensive Pokémon profile.
404
  """
405
  name = pokemon_name.strip().lower()
406
+ profile = [
407
+ get_pokedex_entry(pokemon_name=name),
408
+ get_pokemon_basic_info(pokemon_name=name),
409
+ get_pokemon_abilities(pokemon_name=name),
410
+ get_pokemon_base_stats(pokemon_name=name),
411
+ get_pokemon_evolutions(pokemon_name=name),
412
+ get_pokemon_moves_grouped(pokemon_name=name),
413
+ get_pokemon_held_items(pokemon_name=name),
414
+ get_pokemon_encounter_locations(pokemon_name=name),
415
+ get_pokemon_type_effectiveness(pokemon_name=name),
416
+ get_pokemon_ability_description(pokemon_name=name),
417
+ get_pokemon_sprite(pokemon_name=name)
418
+ ]
419
  return f"{name.title()} Profile:\n\n" + "\n\n".join(profile)
420
 
421
+
422
+ @tool
423
+ def get_pokemon_evolution_visual(pokemon_name: str) -> str:
424
+ """
425
+ Fetches the evolution chain for a Pokémon and generates an HTML visualization with sprites and basic info.
426
+ This tool should be called directly without any code generation.
427
+
428
+ Args:
429
+ pokemon_name: The name or ID of the Pokémon.
430
+
431
+ Returns:
432
+ A string with the evolution chain and instructions to view the HTML visualization.
433
+ """
434
+
435
+ def generate_evolution_html(pokemon_name: str, evolution_data: list) -> str:
436
+ html_template = """
437
+ <!DOCTYPE html>
438
+ <html lang="en">
439
+ <head>
440
+ <meta charset="UTF-8">
441
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
442
+ <title>{title} Evolution Chain</title>
443
+ <style>
444
+ body {{
445
+ font-family: Arial, sans-serif;
446
+ text-align: center;
447
+ background-color: #f0f0f0;
448
+ }}
449
+ h1 {{
450
+ color: #333;
451
+ }}
452
+ .evolution-container {{
453
+ display: flex;
454
+ justify-content: center;
455
+ gap: 20px;
456
+ margin: 20px;
457
+ }}
458
+ .pokemon {{
459
+ background-color: #fff;
460
+ padding: 10px;
461
+ border-radius: 10px;
462
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
463
+ }}
464
+ .pokemon img {{
465
+ width: 100px;
466
+ height: 100px;
467
+ }}
468
+ .pokemon p {{
469
+ margin: 5px 0;
470
+ font-weight: bold;
471
+ }}
472
+ </style>
473
+ </head>
474
+ <body>
475
+ <h1>{title} Evolution Chain</h1>
476
+ <div class="evolution-container">
477
+ {pokemon_entries}
478
+ </div>
479
+ </body>
480
+ </html>
481
+ """
482
+ pokemon_entries = ""
483
+ for name, sprite_url, info in evolution_data:
484
+ pokemon_entries += f"""
485
+ <div class="pokemon">
486
+ <p>{name}</p>
487
+ <img src="{sprite_url}" alt="{name}">
488
+ <p>{info}</p>
489
+ </div>
490
+ """
491
+ return html_template.format(title=pokemon_name.title(), pokemon_entries=pokemon_entries)
492
+
493
+ evolution_chain = get_pokemon_evolutions(pokemon_name=pokemon_name)
494
+ if "Error" in evolution_chain or "No evolution chain" in evolution_chain:
495
+ return evolution_chain
496
+
497
+ names = [name.strip().title() for name in evolution_chain.replace("Evolution chain: ", "").split("→")]
498
+ evolution_data = []
499
+ for name in names:
500
+ sprite_result = get_pokemon_sprite(pokemon_name=name.lower())
501
+ sprite_url = sprite_result.split(": ")[1] if "sprite:" in sprite_result else "https://via.placeholder.com/100"
502
+ info_result = get_pokemon_basic_info(pokemon_name=name.lower())
503
+ info = info_result.replace(f"{name} (", "(").replace("\n",
504
+ ", ") if "Error" not in info_result else "No info available"
505
+ evolution_data.append((name, sprite_url, info))
506
+
507
+ html_content = generate_evolution_html(pokemon_name, evolution_data)
508
+ html_filename = f"{pokemon_name.lower()}_evolution.html"
509
+ with open(html_filename, "w", encoding="utf-8") as f:
510
+ f.write(html_content)
511
+
512
+ return (
513
+ f"{evolution_chain}\n\n"
514
+ f"Evolution visualization saved to '{html_filename}'.\n"
515
+ f"The HTML shows each stage with its sprite and basic info (ID, height, weight, types)."
516
+ )
517
+
518
+
519
+ @tool
520
+ def get_evolution_stats_chart(pokemon_name: str) -> str:
521
+ """
522
+ Generates a Chart.js radar chart comparing base stats for a Pokémon's evolution chain.
523
+ This tool should be called directly without any code generation.
524
+
525
+ Args:
526
+ pokemon_name: The name or ID of the Pokémon.
527
+
528
+ Returns:
529
+ A string with instructions to view the chart JSON.
530
+ """
531
+ evolution_chain = get_pokemon_evolutions(pokemon_name=pokemon_name)
532
+ if "Error" in evolution_chain or "No evolution chain" in evolution_chain:
533
+ return evolution_chain
534
+
535
+ names = [name.strip().title() for name in evolution_chain.replace("Evolution chain: ", "").split("→")]
536
+ datasets = []
537
+ colors = [
538
+ {"bg": "rgba(255, 206, 86, 0.2)", "border": "rgba(255, 206, 86, 1)"},
539
+ {"bg": "rgba(255, 99, 132, 0.2)", "border": "rgba(255, 99, 132, 1)"},
540
+ {"bg": "rgba(54, 162, 235, 0.2)", "border": "rgba(54, 162, 235, 1)"}
541
+ ]
542
+
543
+ for idx, name in enumerate(names):
544
+ stats_result = get_pokemon_base_stats(pokemon_name=name.lower())
545
+ if "Error" in stats_result:
546
+ continue
547
+ stats_dict = {k.split(": ")[0]: int(k.split(": ")[1]) for k in stats_result.split(": ", 1)[1].split(", ")}
548
+ stats_data = [
549
+ stats_dict.get("Hp", 0),
550
+ stats_dict.get("Attack", 0),
551
+ stats_dict.get("Defense", 0),
552
+ stats_dict.get("Special Attack", 0),
553
+ stats_dict.get("Special Defense", 0),
554
+ stats_dict.get("Speed", 0)
555
+ ]
556
+ datasets.append({
557
+ "label": name,
558
+ "data": stats_data,
559
+ "backgroundColor": colors[idx % len(colors)]["bg"],
560
+ "borderColor": colors[idx % len(colors)]["border"],
561
+ "borderWidth": 1
562
+ })
563
+
564
+ chart_config = {
565
+ "type": "radar",
566
+ "data": {
567
+ "labels": ["HP", "Attack", "Defense", "Special Attack", "Special Defense", "Speed"],
568
+ "datasets": datasets
569
+ },
570
+ "options": {
571
+ "scales": {
572
+ "r": {
573
+ "beginAtZero": True,
574
+ "max": 150
575
+ }
576
+ },
577
+ "plugins": {
578
+ "title": {
579
+ "display": True,
580
+ "text": f"{pokemon_name.title()} Evolution Chain Base Stats"
581
+ }
582
+ }
583
+ }
584
+ }
585
+
586
+ chart_filename = f"{pokemon_name.lower()}_evolution_stats.json"
587
+ with open(chart_filename, "w") as f:
588
+ json.dump(chart_config, f, indent=2)
589
+
590
+ return f"Radar chart for {pokemon_name.title()}'s evolution chain stats saved to '{chart_filename}'."
591
+
592
+
593
  final_answer = FinalAnswerTool()
594
 
595
+ model = LiteLLMModel(
596
+ model_id="ollama_chat/qwen2:7b",
597
+ api_base="http://127.0.0.1:11434",
598
+ num_ctx=8192,
599
  )
600
 
601
+ # Create improved prompt templates
602
+ improved_prompts = {
603
+ "system_prompt": """You are a helpful Pokémon information assistant. You have access to many tools to get Pokémon data.
604
+
605
+ IMPORTANT INSTRUCTIONS:
606
+ 1. Always use the available tools directly - never try to write code or import modules
607
+ 2. When asked to call get_pokemon_evolution_visual or get_evolution_stats_chart, call those tools directly
608
+ 3. Never attempt to write Python code, import statements, or create visualizations yourself
609
+ 4. Simply call the appropriate tool function with the pokemon name as argument
610
+ 5. Return the result from the tool call as your final answer
611
+
612
+ Available tools:
613
+ - get_pokemon_evolution_visual: Creates HTML evolution visualization
614
+ - get_evolution_stats_chart: Creates radar chart comparing evolution stats
615
+ - get_pokemon_basic_info: Gets basic Pokémon info
616
+ - get_pokemon_evolutions: Gets evolution chain
617
+ - get_pokemon_base_stats: Gets base stats
618
+ - And many more Pokémon data tools
619
+
620
+ When a user asks you to use a specific tool, call that tool directly.""",
621
+
622
+ "user_prompt": """Human request: {task}
623
+
624
+ Remember: Use the available tools directly. Do not write code or try to import anything.""",
625
+
626
+ "code_execution_system_prompt": """You are a helpful assistant that can execute code to help users. When executing code, be direct and use available tools without attempting to import external modules."""
627
+ }
628
 
629
  agent = CodeAgent(
630
  model=model,
 
642
  get_pokemon_type_effectiveness,
643
  get_pokemon_ability_description,
644
  list_pokemon_by_type,
645
+ get_pokemon_full_profile,
646
+ get_pokemon_evolution_visual,
647
+ get_evolution_stats_chart
648
  ],
649
+ max_steps=3, # Reduced from 6 to force more direct tool usage
650
  verbosity_level=2,
651
+ prompt_templates=improved_prompts
652
  )
653
 
654
+
655
+ def pokemon_ui(pokemon_name):
656
+ if not pokemon_name:
657
+ return "Please enter a Pokémon name (e.g., pikachu).", "", ""
658
+
659
+ try:
660
+ # Use more direct tool calls
661
+ evo_result = get_pokemon_evolution_visual(pokemon_name)
662
+ chart_result = get_evolution_stats_chart(pokemon_name)
663
+
664
+ html_filename = f"{pokemon_name.lower()}_evolution.html"
665
+ evolution_html = ""
666
+ if os.path.exists(html_filename):
667
+ with open(html_filename, "r", encoding="utf-8") as f:
668
+ evolution_html = f.read()
669
+
670
+ chart_filename = f"{pokemon_name.lower()}_evolution_stats.json"
671
+ chart_html = ""
672
+ if os.path.exists(chart_filename):
673
+ with open(chart_filename, "r") as f:
674
+ chart_config = json.load(f)
675
+ chart_html = f"""
676
+ <div style="width: 500px; margin: auto;">
677
+ <canvas id="statsChart"></canvas>
678
+ </div>
679
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
680
+ <script>
681
+ const ctx = document.getElementById('statsChart').getContext('2d');
682
+ new Chart(ctx, {json.dumps(chart_config)});
683
+ </script>
684
+ """
685
+
686
+ return evo_result, evolution_html, chart_html
687
+
688
+ except Exception as e:
689
+ return f"Error processing {pokemon_name}: {str(e)}", "", ""
690
+
691
+
692
+ if __name__ == "__main__":
693
+ iface = gr.Interface(
694
+ fn=pokemon_ui,
695
+ inputs=gr.Textbox(label="Pokemon Name"),
696
+ outputs=[
697
+ gr.HTML(label="Evolution HTML"),
698
+ gr.HTML(label="Evolution Chart HTML"),
699
+ gr.HTML(label="Evolution Stats Chart HTML"),
700
+ ],
701
+ )
702
+ iface.launch(share=True)
prompts.yaml CHANGED
@@ -1,321 +1,326 @@
1
- "system_prompt": |-
2
- You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.
3
- To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
4
- To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
5
-
6
- At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
7
- Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
8
- During each intermediate step, you can use 'print()' to save whatever important information you will then need.
9
- These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
10
- In the end you have to return a final answer using the `final_answer` tool.
11
-
12
- Here are a few examples using notional tools:
13
- ---
14
- Task: "Generate an image of the oldest person in this document."
15
-
16
- Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.
17
- Code:
18
- ```py
19
- answer = document_qa(document=document, question="Who is the oldest person mentioned?")
20
- print(answer)
21
- ```<end_code>
22
- Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
23
-
24
- Thought: I will now generate an image showcasing the oldest person.
25
- Code:
26
- ```py
27
- image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
28
- final_answer(image)
29
- ```<end_code>
30
-
31
- ---
32
- Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
33
-
34
- Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
35
- Code:
36
- ```py
37
- result = 5 + 3 + 1294.678
38
- final_answer(result)
39
- ```<end_code>
40
-
41
- ---
42
- Task:
43
- "Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French.
44
- You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
45
- {'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
46
-
47
- Thought: I will use the following tools: `translator` to translate the question into English and then `image_qa` to answer the question on the input image.
48
- Code:
49
- ```py
50
- translated_question = translator(question=question, src_lang="French", tgt_lang="English")
51
- print(f"The translated question is {translated_question}.")
52
- answer = image_qa(image=image, question=translated_question)
53
- final_answer(f"The answer is {answer}")
54
- ```<end_code>
55
-
56
- ---
57
- Task:
58
- In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
59
- What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
60
-
61
- Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
62
- Code:
63
- ```py
64
- pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
65
- print(pages)
66
- ```<end_code>
67
- Observation:
68
- No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
69
-
70
- Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
71
- Code:
72
- ```py
73
- pages = search(query="1979 interview Stanislaus Ulam")
74
- print(pages)
75
- ```<end_code>
76
- Observation:
77
- Found 6 pages:
78
- [Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
79
-
80
- [Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
81
-
82
- (truncated)
83
-
84
- Thought: I will read the first 2 pages to know more.
85
- Code:
86
- ```py
87
- for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
88
- whole_page = visit_webpage(url)
89
- print(whole_page)
90
- print("\n" + "="*80 + "\n") # Print separator between pages
91
- ```<end_code>
92
- Observation:
93
- Manhattan Project Locations:
94
- Los Alamos, NM
95
- Stanislaus Ulam was a Polish-American mathematician. He worked on the Manhattan Project at Los Alamos and later helped design the hydrogen bomb. In this interview, he discusses his work at
96
- (truncated)
97
-
98
- Thought: I now have the final answer: from the webpages visited, Stanislaus Ulam says of Einstein: "He learned too much mathematics and sort of diminished, it seems to me personally, it seems to me his purely physics creativity." Let's answer in one word.
99
- Code:
100
- ```py
101
- final_answer("diminished")
102
- ```<end_code>
103
-
104
- ---
105
- Task: "Which city has the highest population: Guangzhou or Shanghai?"
106
-
107
- Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities.
108
- Code:
109
- ```py
110
- for city in ["Guangzhou", "Shanghai"]:
111
- print(f"Population {city}:", search(f"{city} population")
112
- ```<end_code>
113
- Observation:
114
- Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
115
- Population Shanghai: '26 million (2019)'
116
-
117
- Thought: Now I know that Shanghai has the highest population.
118
- Code:
119
- ```py
120
- final_answer("Shanghai")
121
- ```<end_code>
122
-
123
- ---
124
- Task: "What is the current age of the pope, raised to the power 0.36?"
125
-
126
- Thought: I will use the tool `wiki` to get the age of the pope, and confirm that with a web search.
127
- Code:
128
- ```py
129
- pope_age_wiki = wiki(query="current pope age")
130
- print("Pope age as per wikipedia:", pope_age_wiki)
131
- pope_age_search = web_search(query="current pope age")
132
- print("Pope age as per google search:", pope_age_search)
133
- ```<end_code>
134
- Observation:
135
- Pope age: "The pope Francis is currently 88 years old."
136
-
137
- Thought: I know that the pope is 88 years old. Let's compute the result using python code.
138
- Code:
139
- ```py
140
- pope_current_age = 88 ** 0.36
141
- final_answer(pope_current_age)
142
- ```<end_code>
143
-
144
- Above example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools:
145
- {%- for tool in tools.values() %}
146
- - {{ tool.name }}: {{ tool.description }}
147
- Takes inputs: {{tool.inputs}}
148
- Returns an output of type: {{tool.output_type}}
149
- {%- endfor %}
150
-
151
- {%- if managed_agents and managed_agents.values() | list %}
152
- You can also give tasks to team members.
153
- Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task', a long string explaining your task.
154
- Given that this team member is a real human, you should be very verbose in your task.
155
- Here is a list of the team members that you can call:
156
- {%- for agent in managed_agents.values() %}
157
- - {{ agent.name }}: {{ agent.description }}
158
- {%- endfor %}
159
- {%- else %}
160
- {%- endif %}
161
-
162
- Here are the rules you should always follow to solve your task:
163
- 1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail.
164
- 2. Use only variables that you have defined!
165
- 3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wiki(query="What is the place where James Bond lives?")'.
166
- 4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
167
- 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
168
- 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
169
- 7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
170
- 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
171
- 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
172
- 10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
173
-
174
- Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
175
- "planning":
176
- "initial_facts": |-
177
- Below I will present you a task.
178
-
179
- You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
180
- To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
181
- Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
182
-
183
- ---
184
- ### 1. Facts given in the task
185
- List here the specific facts given in the task that could help you (there might be nothing here).
186
-
187
- ### 2. Facts to look up
188
- List here any facts that we may need to look up.
189
- Also list where to find each of these, for instance a website, a file... - maybe the task contains some sources that you should re-use here.
190
-
191
- ### 3. Facts to derive
192
- List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
193
-
194
- Keep in mind that "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
195
- ### 1. Facts given in the task
196
- ### 2. Facts to look up
197
- ### 3. Facts to derive
198
- Do not add anything else.
199
- "initial_plan": |-
200
- You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
201
-
202
- Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
203
- This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
204
- Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
205
- After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
206
-
207
- Here is your task:
208
-
209
- Task:
210
- ```
211
- {{task}}
212
- ```
213
- You can leverage these tools:
214
- {%- for tool in tools.values() %}
215
- - {{ tool.name }}: {{ tool.description }}
216
- Takes inputs: {{tool.inputs}}
217
- Returns an output of type: {{tool.output_type}}
218
- {%- endfor %}
219
-
220
- {%- if managed_agents and managed_agents.values() | list %}
221
- You can also give tasks to team members.
222
- Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'request', a long string explaining your request.
223
- Given that this team member is a real human, you should be very verbose in your request.
224
- Here is a list of the team members that you can call:
225
- {%- for agent in managed_agents.values() %}
226
- - {{ agent.name }}: {{ agent.description }}
227
- {%- endfor %}
228
- {%- else %}
229
- {%- endif %}
230
-
231
- List of facts that you know:
232
- ```
233
- {{answer_facts}}
234
- ```
235
-
236
- Now begin! Write your plan below.
237
- "update_facts_pre_messages": |-
238
- You are a world expert at gathering known and unknown facts based on a conversation.
239
- Below you will find a task, and a history of attempts made to solve the task. You will have to produce a list of these:
240
- ### 1. Facts given in the task
241
- ### 2. Facts that we have learned
242
- ### 3. Facts still to look up
243
- ### 4. Facts still to derive
244
- Find the task and history below:
245
- "update_facts_post_messages": |-
246
- Earlier we've built a list of facts.
247
- But since in your previous steps you may have learned useful new facts or invalidated some false ones.
248
- Please update your list of facts based on the previous history, and provide these headings:
249
- ### 1. Facts given in the task
250
- ### 2. Facts that we have learned
251
- ### 3. Facts still to look up
252
- ### 4. Facts still to derive
253
-
254
- Now write your new list of facts below.
255
- "update_plan_pre_messages": |-
256
- You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
257
-
258
- You have been given a task:
259
- ```
260
- {{task}}
261
- ```
262
-
263
- Find below the record of what has been tried so far to solve it. Then you will be asked to make an updated plan to solve the task.
264
- If the previous tries so far have met some success, you can make an updated plan based on these actions.
265
- If you are stalled, you can make a completely new plan starting from scratch.
266
- "update_plan_post_messages": |-
267
- You're still working towards solving this task:
268
- ```
269
- {{task}}
270
- ```
271
-
272
- You can leverage these tools:
273
- {%- for tool in tools.values() %}
274
- - {{ tool.name }}: {{ tool.description }}
275
- Takes inputs: {{tool.inputs}}
276
- Returns an output of type: {{tool.output_type}}
277
- {%- endfor %}
278
-
279
- {%- if managed_agents and managed_agents.values() | list %}
280
- You can also give tasks to team members.
281
- Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task'.
282
- Given that this team member is a real human, you should be very verbose in your task, it should be a long string providing informations as detailed as necessary.
283
- Here is a list of the team members that you can call:
284
- {%- for agent in managed_agents.values() %}
285
- - {{ agent.name }}: {{ agent.description }}
286
- {%- endfor %}
287
- {%- else %}
288
- {%- endif %}
289
-
290
- Here is the up to date list of facts that you know:
291
- ```
292
- {{facts_update}}
293
- ```
294
-
295
- Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
296
- This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
297
- Beware that you have {remaining_steps} steps remaining.
298
- Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
299
- After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
300
-
301
- Now write your new plan below.
302
- "managed_agent":
303
- "task": |-
304
- You're a helpful agent named '{{name}}'.
305
- You have been submitted this task by your manager.
306
- ---
307
- Task:
308
- {{task}}
309
- ---
310
- You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.
311
-
312
- Your final_answer WILL HAVE to contain these parts:
313
- ### 1. Task outcome (short version):
314
- ### 2. Task outcome (extremely detailed version):
315
- ### 3. Additional context (if relevant):
316
-
317
- Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
318
- And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
319
- "report": |-
320
- Here is the final answer from your managed agent '{{name}}':
321
- {{final_answer}}
 
 
 
 
 
 
1
+ #"system_prompt": |-
2
+ # You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.
3
+ # To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
4
+ # To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
5
+ #
6
+ # At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
7
+ # Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
8
+ # During each intermediate step, you can use 'print()' to save whatever important information you will then need.
9
+ # These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
10
+ # In the end you have to return a final answer using the `final_answer` tool.
11
+ #
12
+ # Here are a few examples using notional tools:
13
+ # ---
14
+ # Task: "Generate an image of the oldest person in this document."
15
+ #
16
+ # Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.
17
+ # Code:
18
+ # ```py
19
+ # answer = document_qa(document=document, question="Who is the oldest person mentioned?")
20
+ # print(answer)
21
+ # ```<end_code>
22
+ # Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
23
+ #
24
+ # Thought: I will now generate an image showcasing the oldest person.
25
+ # Code:
26
+ # ```py
27
+ # image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
28
+ # final_answer(image)
29
+ # ```<end_code>
30
+ #
31
+ # ---
32
+ # Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
33
+ #
34
+ # Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
35
+ # Code:
36
+ # ```py
37
+ # result = 5 + 3 + 1294.678
38
+ # final_answer(result)
39
+ # ```<end_code>
40
+ #
41
+ # ---
42
+ # Task:
43
+ # "Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French.
44
+ # You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
45
+ # {'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
46
+ #
47
+ # Thought: I will use the following tools: `translator` to translate the question into English and then `image_qa` to answer the question on the input image.
48
+ # Code:
49
+ # ```py
50
+ # translated_question = translator(question=question, src_lang="French", tgt_lang="English")
51
+ # print(f"The translated question is {translated_question}.")
52
+ # answer = image_qa(image=image, question=translated_question)
53
+ # final_answer(f"The answer is {answer}")
54
+ # ```<end_code>
55
+ #
56
+ # ---
57
+ # Task:
58
+ # In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
59
+ # What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
60
+ #
61
+ # Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
62
+ # Code:
63
+ # ```py
64
+ # pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
65
+ # print(pages)
66
+ # ```<end_code>
67
+ # Observation:
68
+ # No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
69
+ #
70
+ # Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
71
+ # Code:
72
+ # ```py
73
+ # pages = search(query="1979 interview Stanislaus Ulam")
74
+ # print(pages)
75
+ # ```<end_code>
76
+ # Observation:
77
+ # Found 6 pages:
78
+ # [Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
79
+ #
80
+ # [Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
81
+ #
82
+ # (truncated)
83
+ #
84
+ # Thought: I will read the first 2 pages to know more.
85
+ # Code:
86
+ # ```py
87
+ # for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
88
+ # whole_page = visit_webpage(url)
89
+ # print(whole_page)
90
+ # print("\n" + "="*80 + "\n") # Print separator between pages
91
+ # ```<end_code>
92
+ # Observation:
93
+ # Manhattan Project Locations:
94
+ # Los Alamos, NM
95
+ # Stanislaus Ulam was a Polish-American mathematician. He worked on the Manhattan Project at Los Alamos and later helped design the hydrogen bomb. In this interview, he discusses his work at
96
+ # (truncated)
97
+ #
98
+ # Thought: I now have the final answer: from the webpages visited, Stanislaus Ulam says of Einstein: "He learned too much mathematics and sort of diminished, it seems to me personally, it seems to me his purely physics creativity." Let's answer in one word.
99
+ # Code:
100
+ # ```py
101
+ # final_answer("diminished")
102
+ # ```<end_code>
103
+ #
104
+ # ---
105
+ # Task: "Which city has the highest population: Guangzhou or Shanghai?"
106
+ #
107
+ # Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities.
108
+ # Code:
109
+ # ```py
110
+ # for city in ["Guangzhou", "Shanghai"]:
111
+ # print(f"Population {city}:", search(f"{city} population")
112
+ # ```<end_code>
113
+ # Observation:
114
+ # Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
115
+ # Population Shanghai: '26 million (2019)'
116
+ #
117
+ # Thought: Now I know that Shanghai has the highest population.
118
+ # Code:
119
+ # ```py
120
+ # final_answer("Shanghai")
121
+ # ```<end_code>
122
+ #
123
+ # ---
124
+ # Task: "What is the current age of the pope, raised to the power 0.36?"
125
+ #
126
+ # Thought: I will use the tool `wiki` to get the age of the pope, and confirm that with a web search.
127
+ # Code:
128
+ # ```py
129
+ # pope_age_wiki = wiki(query="current pope age")
130
+ # print("Pope age as per wikipedia:", pope_age_wiki)
131
+ # pope_age_search = web_search(query="current pope age")
132
+ # print("Pope age as per google search:", pope_age_search)
133
+ # ```<end_code>
134
+ # Observation:
135
+ # Pope age: "The pope Francis is currently 88 years old."
136
+ #
137
+ # Thought: I know that the pope is 88 years old. Let's compute the result using python code.
138
+ # Code:
139
+ # ```py
140
+ # pope_current_age = 88 ** 0.36
141
+ # final_answer(pope_current_age)
142
+ # ```<end_code>
143
+ #
144
+ # Above example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools:
145
+ # {%- for tool in tools.values() %}
146
+ # - {{ tool.name }}: {{ tool.description }}
147
+ # Takes inputs: {{tool.inputs}}
148
+ # Returns an output of type: {{tool.output_type}}
149
+ # {%- endfor %}
150
+ #
151
+ # {%- if managed_agents and managed_agents.values() | list %}
152
+ # You can also give tasks to team members.
153
+ # Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task', a long string explaining your task.
154
+ # Given that this team member is a real human, you should be very verbose in your task.
155
+ # Here is a list of the team members that you can call:
156
+ # {%- for agent in managed_agents.values() %}
157
+ # - {{ agent.name }}: {{ agent.description }}
158
+ # {%- endfor %}
159
+ # {%- else %}
160
+ # {%- endif %}
161
+ #
162
+ # Here are the rules you should always follow to solve your task:
163
+ # 1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail.
164
+ # 2. Use only variables that you have defined!
165
+ # 3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wiki(query="What is the place where James Bond lives?")'.
166
+ # 4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
167
+ # 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
168
+ # 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
169
+ # 7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
170
+ # 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
171
+ # 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
172
+ # 10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
173
+ #
174
+ # Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
175
+ #"planning":
176
+ # "initial_facts": |-
177
+ # Below I will present you a task.
178
+ #
179
+ # You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
180
+ # To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
181
+ # Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
182
+ #
183
+ # ---
184
+ # ### 1. Facts given in the task
185
+ # List here the specific facts given in the task that could help you (there might be nothing here).
186
+ #
187
+ # ### 2. Facts to look up
188
+ # List here any facts that we may need to look up.
189
+ # Also list where to find each of these, for instance a website, a file... - maybe the task contains some sources that you should re-use here.
190
+ #
191
+ # ### 3. Facts to derive
192
+ # List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
193
+ #
194
+ # Keep in mind that "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
195
+ # ### 1. Facts given in the task
196
+ # ### 2. Facts to look up
197
+ # ### 3. Facts to derive
198
+ # Do not add anything else.
199
+ # "initial_plan": |-
200
+ # You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
201
+ #
202
+ # Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
203
+ # This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
204
+ # Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
205
+ # After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
206
+ #
207
+ # Here is your task:
208
+ #
209
+ # Task:
210
+ # ```
211
+ # {{task}}
212
+ # ```
213
+ # You can leverage these tools:
214
+ # {%- for tool in tools.values() %}
215
+ # - {{ tool.name }}: {{ tool.description }}
216
+ # Takes inputs: {{tool.inputs}}
217
+ # Returns an output of type: {{tool.output_type}}
218
+ # {%- endfor %}
219
+ #
220
+ # {%- if managed_agents and managed_agents.values() | list %}
221
+ # You can also give tasks to team members.
222
+ # Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'request', a long string explaining your request.
223
+ # Given that this team member is a real human, you should be very verbose in your request.
224
+ # Here is a list of the team members that you can call:
225
+ # {%- for agent in managed_agents.values() %}
226
+ # - {{ agent.name }}: {{ agent.description }}
227
+ # {%- endfor %}
228
+ # {%- else %}
229
+ # {%- endif %}
230
+ #
231
+ # List of facts that you know:
232
+ # ```
233
+ # {{answer_facts}}
234
+ # ```
235
+ #
236
+ # Now begin! Write your plan below.
237
+ # "update_facts_pre_messages": |-
238
+ # You are a world expert at gathering known and unknown facts based on a conversation.
239
+ # Below you will find a task, and a history of attempts made to solve the task. You will have to produce a list of these:
240
+ # ### 1. Facts given in the task
241
+ # ### 2. Facts that we have learned
242
+ # ### 3. Facts still to look up
243
+ # ### 4. Facts still to derive
244
+ # Find the task and history below:
245
+ # "update_facts_post_messages": |-
246
+ # Earlier we've built a list of facts.
247
+ # But since in your previous steps you may have learned useful new facts or invalidated some false ones.
248
+ # Please update your list of facts based on the previous history, and provide these headings:
249
+ # ### 1. Facts given in the task
250
+ # ### 2. Facts that we have learned
251
+ # ### 3. Facts still to look up
252
+ # ### 4. Facts still to derive
253
+ #
254
+ # Now write your new list of facts below.
255
+ # "update_plan_pre_messages": |-
256
+ # You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
257
+ #
258
+ # You have been given a task:
259
+ # ```
260
+ # {{task}}
261
+ # ```
262
+ #
263
+ # Find below the record of what has been tried so far to solve it. Then you will be asked to make an updated plan to solve the task.
264
+ # If the previous tries so far have met some success, you can make an updated plan based on these actions.
265
+ # If you are stalled, you can make a completely new plan starting from scratch.
266
+ # "update_plan_post_messages": |-
267
+ # You're still working towards solving this task:
268
+ # ```
269
+ # {{task}}
270
+ # ```
271
+ #
272
+ # You can leverage these tools:
273
+ # {%- for tool in tools.values() %}
274
+ # - {{ tool.name }}: {{ tool.description }}
275
+ # Takes inputs: {{tool.inputs}}
276
+ # Returns an output of type: {{tool.output_type}}
277
+ # {%- endfor %}
278
+ #
279
+ # {%- if managed_agents and managed_agents.values() | list %}
280
+ # You can also give tasks to team members.
281
+ # Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task'.
282
+ # Given that this team member is a real human, you should be very verbose in your task, it should be a long string providing informations as detailed as necessary.
283
+ # Here is a list of the team members that you can call:
284
+ # {%- for agent in managed_agents.values() %}
285
+ # - {{ agent.name }}: {{ agent.description }}
286
+ # {%- endfor %}
287
+ # {%- else %}
288
+ # {%- endif %}
289
+ #
290
+ # Here is the up to date list of facts that you know:
291
+ # ```
292
+ # {{facts_update}}
293
+ # ```
294
+ #
295
+ # Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
296
+ # This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
297
+ # Beware that you have {remaining_steps} steps remaining.
298
+ # Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
299
+ # After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
300
+ #
301
+ # Now write your new plan below.
302
+ #"managed_agent":
303
+ # "task": |-
304
+ # You're a helpful agent named '{{name}}'.
305
+ # You have been submitted this task by your manager.
306
+ # ---
307
+ # Task:
308
+ # {{task}}
309
+ # ---
310
+ # You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.
311
+ #
312
+ # Your final_answer WILL HAVE to contain these parts:
313
+ # ### 1. Task outcome (short version):
314
+ # ### 2. Task outcome (extremely detailed version):
315
+ # ### 3. Additional context (if relevant):
316
+ #
317
+ # Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
318
+ # And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
319
+ # "report": |-
320
+ # Here is the final answer from your managed agent '{{name}}':
321
+ # {{final_answer}}
322
+
323
+ system_prompt: |
324
+ You are a specialized Pokémon assistant.
325
+ Use the provided tools to answer Pokémon-related queries.
326
+ For visualization requests, use get_pokemon_evolution_visual and get_evolution_stats_chart.
requirements.txt CHANGED
@@ -1,5 +1,8 @@
1
- markdownify
2
  smolagents==1.13.0
3
- requests
4
  duckduckgo_search
5
  pandas
 
 
 
 
1
+ markdownify~=1.1.0
2
  smolagents==1.13.0
3
+ requests~=2.32.4
4
  duckduckgo_search
5
  pandas
6
+
7
+ duckduckgo_search~=8.0.3
8
+ PyYAML~=6.0.2