Aktraiser commited on
Commit
e12f601
·
verified ·
1 Parent(s): f5d6b6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
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 games via TheRundown API.
41
 
42
  Returns:
43
- A string containing a human-readable list of upcoming games.
44
  """
45
- url = "https://api.apilayer.com/therundown/sports/4/events" # Replace with the NBA-specific endpoint if available.
 
 
 
46
  headers = {
47
  "apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
48
  }
 
49
  response = requests.get(url, headers=headers)
50
  if response.status_code == 200:
51
- events = response.json()
52
- # Suppose 'events' is a dictionary containing a list of games under the key "events"
53
- games = []
54
- for event in events.get("events", []):
55
- # Extract relevant information: date, teams, etc.
56
- date = event.get("start_time", "Unknown date")
57
- teams = event.get("teams", "Game info not defined")
58
- games.append(f"{date} : {teams}")
59
- if games:
60
- return "\n".join(games)
 
61
  else:
62
- return "No NBA games found in the response."
63
  else:
64
- return f"Error retrieving NBA games: {response.status_code}"
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 the match details in the format "TeamA vs TeamB".
73
 
74
  Returns:
75
- A string with the prediction (e.g., "The prediction is that TeamA will win.").
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 "Incorrect match_info format. Please provide teams in the format 'TeamA vs TeamB'."
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()