roieri100 commited on
Commit
eb67010
·
verified ·
1 Parent(s): 3522cea

Add NBA API static players data tool

Browse files
Files changed (1) hide show
  1. app.py +44 -1
app.py CHANGED
@@ -4,9 +4,52 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
 
7
 
8
  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
@@ -55,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone, image_generation_tool], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from nba_api.stats.static import players
8
+ from nba_api.stats.endpoints import commonplayerinfo
9
+
10
 
11
  from Gradio_UI import GradioUI
12
 
13
+
14
+ def get_player(name):
15
+ player = players.find_players_by_full_name(name)
16
+ if player:
17
+ return player[0]
18
+ return None
19
+
20
+ @tool
21
+ def get_player_info(player_name:str): -> dict
22
+ """
23
+ A tool that gets details about an NBA player using the NBA API.
24
+ the details that are returned in the dictionary are:
25
+ Name, Height, Weight, Birth Date, College, Country, Draft Year, Draft Round, Draft Number, Years Pro, Current Team
26
+ Args:
27
+ player_name: the full name of the NBA player (e.g. Kobe Bryant)
28
+ """
29
+ # Fetch player bio details
30
+ player_id = get_player(player_name)['id']
31
+ player_info = commonplayerinfo.CommonPlayerInfo(player_id=player_id)
32
+ data = player_info.get_dict()
33
+ info = data['resultSets'][0]['rowSet'][0] # The first (and only) row
34
+
35
+ # Dictionary mapping for extracted values
36
+ player_details = {
37
+ "Name": info[3], # Full name
38
+ "Height": info[11], # Height in feet-inches
39
+ "Weight": info[12], # Weight in pounds
40
+ "Birth Date": info[7].split('T')[0], # Date of birth
41
+ "College": info[8], # College name
42
+ "Country": info[9], # Country of birth
43
+ "Draft Year": info[29], # Year drafted
44
+ "Draft Round": info[30], # Draft round
45
+ "Draft Number": info[31], # Pick number
46
+ "Years Pro": info[13], # Years in the NBA
47
+ "Team": info[20] if info[20] != '' else 'NA' # Current team
48
+ }
49
+ return player_details
50
+
51
+
52
+
53
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
54
  @tool
55
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
98
 
99
  agent = CodeAgent(
100
  model=model,
101
+ tools=[final_answer, get_current_time_in_timezone, get_player_info], ## add your tools here (don't remove final answer)
102
  max_steps=6,
103
  verbosity_level=1,
104
  grammar=None,