LucaR84 commited on
Commit
8edca5e
·
verified ·
1 Parent(s): 33c368a

Update app.py

Browse files

added a new tool to retrieves the areas where a pokemon can be found

Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -9,6 +9,69 @@ from tools.final_answer import FinalAnswerTool
9
  from Gradio_UI import GradioUI
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
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+ @tool
13
+ def pokemon_locations(pokemon_name: str) -> dict:
14
+
15
+ """A tool that retrieves the areas where Pokémon can be found.
16
+ Args:
17
+ pokemon_name: the name of the pokemon
18
+ Returns:
19
+ A json with the locations, here an example of a json response:
20
+ [
21
+ {
22
+ "location_area": {
23
+ "name": "kanto-route-2-south-towards-viridian-city",
24
+ "url": "https://pokeapi.co/api/v2/location-area/296/"
25
+ },
26
+ "version_details": [
27
+ {
28
+ "max_chance": 10,
29
+ "encounter_details": [
30
+ {
31
+ "min_level": 7,
32
+ "max_level": 7,
33
+ "condition_values": [
34
+ {
35
+ "name": "time-morning",
36
+ "url": "https://pokeapi.co/api/v2/encounter-condition-value/3/"
37
+ }
38
+ ],
39
+ "chance": 5,
40
+ "method": {
41
+ "name": "walk",
42
+ "url": "https://pokeapi.co/api/v2/encounter-method/1/"
43
+ }
44
+ }
45
+ ],
46
+ "version": {
47
+ "name": "heartgold",
48
+ "url": "https://pokeapi.co/api/v2/version/15/"
49
+ }
50
+ }
51
+ ]
52
+ }
53
+ ]
54
+ """
55
+ try:
56
+ url = "https://pokeapi.co/api/v2/pokemon/"+pokemon_name+"/encounters"
57
+ # Send a GET request to the URL
58
+ response = requests.get(url)
59
+ json_data = "{}"
60
+ # Check if the request was successful
61
+ if response.status_code == 200:
62
+ # Try to parse the response as JSON
63
+ try:
64
+ json_data = response.json()
65
+ except ValueError as e:
66
+ print(f"Failed to parse JSON: {e}")
67
+ else:
68
+ print(f"Failed to retrieve data. Status code: {response.status_code}")
69
+ except requests.exceptions.RequestException as e:
70
+ print(f"An error occurred: {e}")
71
+
72
+ return json_data
73
+
74
+
75
  @tool
76
  def get_pokemon_detail(pokemon_name:str)-> dict: #it's import to specify the return type
77
  #Keep this format for the description / args / args description but feel free to modify the tool