Spaces:
Sleeping
Sleeping
Add get_today_football_matches tool
Browse filesMy agent to search all football matches for today
app.py
CHANGED
|
@@ -32,6 +32,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
@@ -55,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
+
|
| 36 |
+
@tool
|
| 37 |
+
def get_today_football_matches() -> List[Dict[str, str]]:
|
| 38 |
+
"""Fetches all football matches scheduled for today using ScoreBat API.
|
| 39 |
+
|
| 40 |
+
Returns:
|
| 41 |
+
A list of dictionaries containing match details such as teams, time, and competition.
|
| 42 |
+
"""
|
| 43 |
+
url = "https://www.scorebat.com/video-api/v3/"
|
| 44 |
+
response = requests.get(url)
|
| 45 |
+
|
| 46 |
+
if response.status_code != 200:
|
| 47 |
+
return [{"error": f"Failed to fetch data, status code: {response.status_code}"}]
|
| 48 |
+
|
| 49 |
+
data = response.json()
|
| 50 |
+
today = datetime.today().strftime('%Y-%m-%d')
|
| 51 |
+
|
| 52 |
+
matches = []
|
| 53 |
+
for match in data.get("response", []):
|
| 54 |
+
if today in match.get("date", ""):
|
| 55 |
+
matches.append({
|
| 56 |
+
"home_team": match.get("title", "").split(" vs ")[0],
|
| 57 |
+
"away_team": match.get("title", "").split(" vs ")[-1],
|
| 58 |
+
"competition": match.get("competition", ""),
|
| 59 |
+
"time": match.get("date"),
|
| 60 |
+
"video_url": match.get("videos")[0]["embed"] if match.get("videos") else "No video",
|
| 61 |
+
})
|
| 62 |
+
|
| 63 |
+
return matches
|
| 64 |
|
| 65 |
|
| 66 |
final_answer = FinalAnswerTool()
|
|
|
|
| 84 |
|
| 85 |
agent = CodeAgent(
|
| 86 |
model=model,
|
| 87 |
+
tools=[final_answer, get_current_time_in_timezone, my_custom_tool, get_today_football_matches], ## add your tools here (don't remove final answer)
|
| 88 |
max_steps=6,
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|