Spaces:
Sleeping
Sleeping
Update nb_tool.py
Browse files- nb_tool.py +40 -0
nb_tool.py
CHANGED
@@ -22,6 +22,9 @@ def get_npb_player_info(player_name: str) -> str:
|
|
22 |
Returns:
|
23 |
- str: The player's jersey number and team name, or an error message if not found.
|
24 |
"""
|
|
|
|
|
|
|
25 |
try:
|
26 |
# Search using Tavily for the NPB English profile page
|
27 |
query = f"site:npb.jp/bis/eng/players {player_name}"
|
@@ -57,6 +60,43 @@ def get_npb_player_info(player_name: str) -> str:
|
|
57 |
# print(get_npb_player_info("Taisho Tamai"))
|
58 |
|
59 |
@tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
def get_team_players_by_season(team_name: str, year: int) -> list[str]:
|
61 |
"""
|
62 |
Given a team name and year, returns the list of player names for that NPB season.
|
|
|
22 |
Returns:
|
23 |
- str: The player's jersey number and team name, or an error message if not found.
|
24 |
"""
|
25 |
+
return get_npb_player_info_(player_name)
|
26 |
+
|
27 |
+
def get_npb_player_info_(player_name: str) -> str:
|
28 |
try:
|
29 |
# Search using Tavily for the NPB English profile page
|
30 |
query = f"site:npb.jp/bis/eng/players {player_name}"
|
|
|
60 |
# print(get_npb_player_info("Taisho Tamai"))
|
61 |
|
62 |
@tool
|
63 |
+
def get_team_roster(team_name: str, year: int) -> list[dict]:
|
64 |
+
"""
|
65 |
+
Returns the team roster for a given NPB team and season.
|
66 |
+
|
67 |
+
Each player is represented as a dict with:
|
68 |
+
- name: "Last, First"
|
69 |
+
- number: jersey number (str or None if not found)
|
70 |
+
- role (pitcher, etc.)
|
71 |
+
|
72 |
+
Parameters:
|
73 |
+
- team_name (str): e.g., "Yomiuri Giants"
|
74 |
+
- year (int): e.g., 2023
|
75 |
+
|
76 |
+
Returns:
|
77 |
+
- List of dicts representing players.
|
78 |
+
"""
|
79 |
+
roster = []
|
80 |
+
player_names = get_team_players_by_season(team_name, year)
|
81 |
+
|
82 |
+
for player_name in player_names:
|
83 |
+
# Get player info
|
84 |
+
info = get_npb_player_info_(player_name)
|
85 |
+
|
86 |
+
# Try to extract number from the response
|
87 |
+
match = re.search(r"#(\d+)", info)
|
88 |
+
number = match.group(1) if match else None
|
89 |
+
|
90 |
+
roster.append({
|
91 |
+
"name": player_name,
|
92 |
+
"number": number,
|
93 |
+
"role": "Pitcher" # Static for now
|
94 |
+
})
|
95 |
+
|
96 |
+
return roster
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
def get_team_players_by_season(team_name: str, year: int) -> list[str]:
|
101 |
"""
|
102 |
Given a team name and year, returns the list of player names for that NPB season.
|