Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,31 +37,36 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
37 |
@tool
|
38 |
def get_nba_matches() -> str:
|
39 |
"""
|
40 |
-
A tool that retrieves upcoming NBA
|
41 |
|
42 |
Returns:
|
43 |
-
A
|
44 |
"""
|
45 |
-
|
|
|
|
|
|
|
46 |
headers = {
|
47 |
"apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
|
48 |
}
|
|
|
49 |
response = requests.get(url, headers=headers)
|
50 |
if response.status_code == 200:
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
else:
|
62 |
-
return "No NBA
|
63 |
else:
|
64 |
-
return f"Error retrieving NBA
|
65 |
|
66 |
@tool
|
67 |
def predict_nba_match(match_info: str) -> str:
|
@@ -69,19 +74,18 @@ def predict_nba_match(match_info: str) -> str:
|
|
69 |
A tool that generates a prediction for an NBA match.
|
70 |
|
71 |
Args:
|
72 |
-
match_info: A string containing
|
73 |
|
74 |
Returns:
|
75 |
-
A string with the prediction
|
76 |
"""
|
77 |
import random
|
78 |
-
# Assume match_info is in the format "TeamA vs TeamB"
|
79 |
teams = match_info.split(" vs ")
|
80 |
if len(teams) == 2:
|
81 |
prediction = random.choice(teams)
|
82 |
return f"The prediction is that {prediction} will win."
|
83 |
else:
|
84 |
-
return "
|
85 |
|
86 |
|
87 |
final_answer = FinalAnswerTool()
|
|
|
37 |
@tool
|
38 |
def get_nba_matches() -> str:
|
39 |
"""
|
40 |
+
A tool that retrieves upcoming NBA matches using TheRundown API.
|
41 |
|
42 |
Returns:
|
43 |
+
A human-readable string listing the upcoming NBA matches.
|
44 |
"""
|
45 |
+
import requests
|
46 |
+
# Replace the endpoint below with the correct NBA events endpoint if available.
|
47 |
+
# Here we assume sport_id 4 corresponds to NBA and that the '/events' endpoint returns the matches.
|
48 |
+
url = "https://api.apilayer.com/therundown/sports/4/events"
|
49 |
headers = {
|
50 |
"apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
|
51 |
}
|
52 |
+
|
53 |
response = requests.get(url, headers=headers)
|
54 |
if response.status_code == 200:
|
55 |
+
data = response.json()
|
56 |
+
matches = []
|
57 |
+
# Parse the JSON based on the API's structure.
|
58 |
+
# (Adjust the keys below according to the actual response format.)
|
59 |
+
for event in data.get("events", []):
|
60 |
+
start_time = event.get("start_time", "Unknown time")
|
61 |
+
home_team = event.get("home_team", "Home team not available")
|
62 |
+
away_team = event.get("away_team", "Away team not available")
|
63 |
+
matches.append(f"{start_time}: {home_team} vs {away_team}")
|
64 |
+
if matches:
|
65 |
+
return "\n".join(matches)
|
66 |
else:
|
67 |
+
return "No NBA matches found."
|
68 |
else:
|
69 |
+
return f"Error retrieving NBA matches: {response.status_code}"
|
70 |
|
71 |
@tool
|
72 |
def predict_nba_match(match_info: str) -> str:
|
|
|
74 |
A tool that generates a prediction for an NBA match.
|
75 |
|
76 |
Args:
|
77 |
+
match_info: A string containing match details in the format "TeamA vs TeamB".
|
78 |
|
79 |
Returns:
|
80 |
+
A string with the prediction, e.g. "The prediction is that TeamA will win.".
|
81 |
"""
|
82 |
import random
|
|
|
83 |
teams = match_info.split(" vs ")
|
84 |
if len(teams) == 2:
|
85 |
prediction = random.choice(teams)
|
86 |
return f"The prediction is that {prediction} will win."
|
87 |
else:
|
88 |
+
return "Invalid match format. Please provide match details in the format 'TeamA vs TeamB'."
|
89 |
|
90 |
|
91 |
final_answer = FinalAnswerTool()
|