Spaces:
Sleeping
Sleeping
Updated get_top_ranked_team to return multiple teams
Browse files
app.py
CHANGED
|
@@ -3,20 +3,21 @@ from bs4 import BeautifulSoup
|
|
| 3 |
import datetime
|
| 4 |
import requests
|
| 5 |
import pytz
|
|
|
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
"""A tool that returns a
|
| 14 |
This dictionary includes the team name, their board name (i.e. the short form of their name) and their school ID.
|
| 15 |
Args:
|
| 16 |
division: A string representing the division. This can only take values from ["NCAA Division I", "NCAA Division II", "NCAA Division III].
|
| 17 |
gender: A string representing the gender. This can only take values from ["Women", "Men"].
|
| 18 |
"""
|
| 19 |
-
api_url = f"https://scoreboard.clippd.com/api/rankings/leaderboard?rankingType=Team&gender={gender}&division={division}&sortField=rank&season=2025&limit=
|
| 20 |
headers = {
|
| 21 |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
|
| 22 |
'Content-Type': 'application/json'
|
|
@@ -24,8 +25,11 @@ def get_top_ranked_team(division:str, gender:str)-> dict:
|
|
| 24 |
response = requests.get(api_url, headers=headers)
|
| 25 |
if response.status_code == 200:
|
| 26 |
data = response.json()
|
| 27 |
-
|
| 28 |
-
school_info =
|
|
|
|
|
|
|
|
|
|
| 29 |
return school_info
|
| 30 |
else:
|
| 31 |
return "Error: Unable to fetch the school information."
|
|
@@ -126,7 +130,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 126 |
|
| 127 |
agent = CodeAgent(
|
| 128 |
model=model,
|
| 129 |
-
tools=[final_answer,
|
| 130 |
max_steps=6,
|
| 131 |
verbosity_level=1,
|
| 132 |
grammar=None,
|
|
|
|
| 3 |
import datetime
|
| 4 |
import requests
|
| 5 |
import pytz
|
| 6 |
+
from typing import List
|
| 7 |
import yaml
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
@tool
|
| 13 |
+
def get_top_ranked_teams(division:str, gender:str, num_teams:int)-> List[dict]:
|
| 14 |
+
"""A tool that returns a list of dictionaries containing information about the top "num_teams" ranked teams for a given division and gender.
|
| 15 |
This dictionary includes the team name, their board name (i.e. the short form of their name) and their school ID.
|
| 16 |
Args:
|
| 17 |
division: A string representing the division. This can only take values from ["NCAA Division I", "NCAA Division II", "NCAA Division III].
|
| 18 |
gender: A string representing the gender. This can only take values from ["Women", "Men"].
|
| 19 |
"""
|
| 20 |
+
api_url = f"https://scoreboard.clippd.com/api/rankings/leaderboard?rankingType=Team&gender={gender}&division={division}&sortField=rank&season=2025&limit={num_teams}&offset=0"
|
| 21 |
headers = {
|
| 22 |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
|
| 23 |
'Content-Type': 'application/json'
|
|
|
|
| 25 |
response = requests.get(api_url, headers=headers)
|
| 26 |
if response.status_code == 200:
|
| 27 |
data = response.json()
|
| 28 |
+
schools = data.get("results", [{}])
|
| 29 |
+
school_info = []
|
| 30 |
+
for school in schools:
|
| 31 |
+
school_data = {k: school[k] for k in ["schoolName", "boardName", "schoolId", "eventsWon", "eventsTop3", "strokePlayEvents", "matchPlayEvents"] if k in school}
|
| 32 |
+
school_info.append(school_data)
|
| 33 |
return school_info
|
| 34 |
else:
|
| 35 |
return "Error: Unable to fetch the school information."
|
|
|
|
| 130 |
|
| 131 |
agent = CodeAgent(
|
| 132 |
model=model,
|
| 133 |
+
tools=[final_answer, get_top_ranked_teams, get_team_results], ## add your tools here (don't remove final answer)
|
| 134 |
max_steps=6,
|
| 135 |
verbosity_level=1,
|
| 136 |
grammar=None,
|