LucaR84 commited on
Commit
9becad4
·
verified ·
1 Parent(s): 2a198ab

Update app.py

Browse files

Added the tool for pokemon database retrieval

Files changed (1) hide show
  1. app.py +102 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
@@ -9,14 +10,109 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -56,7 +152,7 @@ with open("prompts.yaml", 'r') as stream:
56
 
57
  agent = CodeAgent(
58
  model=model,
59
- tools=[my_custom_tool, image_generation_tool, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
60
  max_steps=6,
61
  verbosity_level=1,
62
  grammar=None,
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
+ import json
5
  import pytz
6
  import yaml
7
  from tools.final_answer import FinalAnswerTool
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def get_pokemon_detail(pokemon_name:str)-> dict: #it's import to specify the return type
14
  #Keep this format for the description / args / args description but feel free to modify the tool
15
+ """A tool that retrieves the characteristic of a pokemon
16
  Args:
17
+ pokemon_name: the name of the pokemon
18
+ Returns:
19
+ A json with the pokemon details, here an example of a partial json response for the pokemon 'clefairy':
20
+ {
21
+ "id": 35,
22
+ "name": "clefairy",
23
+ "base_experience": 113,
24
+ "height": 6,
25
+ "is_default": true,
26
+ "order": 56,
27
+ "weight": 75,
28
+ "abilities": [
29
+ {
30
+ "is_hidden": true,
31
+ "slot": 3,
32
+ "ability": {
33
+ "name": "friend-guard",
34
+ "url": "https://pokeapi.co/api/v2/ability/132/"
35
+ }
36
+ }
37
+ ],
38
+ "forms": [
39
+ {
40
+ "name": "clefairy",
41
+ "url": "https://pokeapi.co/api/v2/pokemon-form/35/"
42
+ }
43
+ ],
44
+ "game_indices": [
45
+ {
46
+ "game_index": 35,
47
+ "version": {
48
+ "name": "white-2",
49
+ "url": "https://pokeapi.co/api/v2/version/22/"
50
+ }
51
+ }
52
+ ],
53
+ "held_items": [
54
+ {
55
+ "item": {
56
+ "name": "moon-stone",
57
+ "url": "https://pokeapi.co/api/v2/item/81/"
58
+ },
59
+ "version_details": [
60
+ {
61
+ "rarity": 5,
62
+ "version": {
63
+ "name": "ruby",
64
+ "url": "https://pokeapi.co/api/v2/version/7/"
65
+ }
66
+ }
67
+ ]
68
+ }
69
+ ],
70
+ "location_area_encounters": "/api/v2/pokemon/35/encounters",
71
+ "moves": [
72
+ {
73
+ "move": {
74
+ "name": "pound",
75
+ "url": "https://pokeapi.co/api/v2/move/1/"
76
+ },
77
+ "version_group_details": [
78
+ {
79
+ "level_learned_at": 1,
80
+ "version_group": {
81
+ "name": "red-blue",
82
+ "url": "https://pokeapi.co/api/v2/version-group/1/"
83
+ },
84
+ "move_learn_method": {
85
+ "name": "level-up",
86
+ "url": "https://pokeapi.co/api/v2/move-learn-method/1/"
87
+ }
88
+ }
89
+ ]
90
+ }
91
+ ],
92
+ "species": {
93
+ "name": "clefairy",
94
+ "url": "https://pokeapi.co/api/v2/pokemon-species/35/"
95
+ }
96
+ }
97
  """
98
+ try:
99
+ url = "https://pokeapi.co/api/v2/pokemon/"+pokemon_name+"/"
100
+ # Send a GET request to the URL
101
+ response = requests.get(url)
102
+
103
+ # Check if the request was successful
104
+ if response.status_code == 200:
105
+ # Try to parse the response as JSON
106
+ try:
107
+ json_data = response.json()
108
+ except ValueError as e:
109
+ print(f"Failed to parse JSON: {e}")
110
+ else:
111
+ print(f"Failed to retrieve data. Status code: {response.status_code}")
112
+ except requests.exceptions.RequestException as e:
113
+ print(f"An error occurred: {e}")
114
+
115
+ return jsondata
116
 
117
  @tool
118
  def get_current_time_in_timezone(timezone: str) -> str:
 
152
 
153
  agent = CodeAgent(
154
  model=model,
155
+ tools=[get_pokemon_detail, image_generation_tool, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
156
  max_steps=6,
157
  verbosity_level=1,
158
  grammar=None,