robertgil commited on
Commit
272f7ee
·
verified ·
1 Parent(s): 09551d5
Files changed (1) hide show
  1. app.py +28 -60
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -12,75 +13,42 @@ rapid_api_key=os.environ["RAPID_KEY"]
12
 
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
- def get_football_results(team1:str, team2:str)-> str: #it's import to specify the return type
16
- #Keep this format for the description / args / args description but feel free to modify the tool
17
  """A tool that connect to an API that provides live football data and compares the stats of two teams in the English Premier League, then it returns a text response
18
- where you should look for those football teams given and return a comparison of the current stats. Then with the response you should reflect on the comparison commenting on the performance
19
  Args:
20
- team1: The first argument provides one of the football teams to check
21
- team2: The second football team to check
22
  """
23
  url = "https://free-api-live-football-data.p.rapidapi.com/football-get-standing-home"
24
 
25
- querystring = {"leagueid":"47"} #British Premier League
26
 
27
  headers = {
28
- "x-rapidapi-key": rapid_api_key,
29
- "x-rapidapi-host": "free-api-live-football-data.p.rapidapi.com"
30
  }
31
-
32
- try:
33
- response = requests.get(url, headers=headers, params=querystring)
34
- response.raise_for_status() # Raise exception for bad responses
35
-
36
- data = response.json()
37
-
38
- # Extract standings data from response
39
- standings = data.get('standing', [])
40
-
41
- # Find the data for both requested teams
42
- team1_data = None
43
- team2_data = None
44
-
45
- for team in standings:
46
- if team1.lower() in team.get('team_name', '').lower():
47
- team1_data = team
48
- if team2.lower() in team.get('team_name', '').lower():
49
- team2_data = team
50
-
51
- # Generate the comparison text
52
- if team1_data and team2_data:
53
- comparison = f"## {team1_data['team_name']} vs {team2_data['team_name']} Comparison\n\n"
54
- comparison += f"### {team1_data['team_name']}:\n"
55
- comparison += f"- Position: {team1_data.get('place', 'N/A')}\n"
56
- comparison += f"- Matches Played: {team1_data.get('played', 'N/A')}\n"
57
- comparison += f"- Wins: {team1_data.get('win', 'N/A')}\n"
58
- comparison += f"- Draws: {team1_data.get('draw', 'N/A')}\n"
59
- comparison += f"- Losses: {team1_data.get('loss', 'N/A')}\n"
60
- comparison += f"- Goals For: {team1_data.get('goals_for', 'N/A')}\n"
61
- comparison += f"- Goals Against: {team1_data.get('goals_against', 'N/A')}\n"
62
- comparison += f"- Points: {team1_data.get('points', 'N/A')}\n\n"
63
-
64
- comparison += f"### {team2_data['team_name']}:\n"
65
- comparison += f"- Position: {team2_data.get('place', 'N/A')}\n"
66
- comparison += f"- Matches Played: {team2_data.get('played', 'N/A')}\n"
67
- comparison += f"- Wins: {team2_data.get('win', 'N/A')}\n"
68
- comparison += f"- Draws: {team2_data.get('draw', 'N/A')}\n"
69
- comparison += f"- Losses: {team2_data.get('loss', 'N/A')}\n"
70
- comparison += f"- Goals For: {team2_data.get('goals_for', 'N/A')}\n"
71
- comparison += f"- Goals Against: {team2_data.get('goals_against', 'N/A')}\n"
72
- comparison += f"- Points: {team2_data.get('points', 'N/A')}\n"
73
-
74
- return comparison
75
- elif not team1_data and not team2_data:
76
- return f"Could not find data for either {team1} or {team2} in the Premier League standings."
77
- elif not team1_data:
78
- return f"Could not find data for {team1} in the Premier League standings."
79
- else:
80
- return f"Could not find data for {team2} in the Premier League standings."
81
 
82
- except Exception as e:
83
- return f"Error retrieving or processing football data: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  @tool
86
  def get_current_time_in_timezone(timezone: str) -> str:
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ from transformers import pipeline
3
  import datetime
4
  import requests
5
  import pytz
 
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
+ def get_football_results(arg1: str, arg2: str) -> str: # it's import to specify the return type
17
+ # Keep this format for the description / args / args description but feel free to modify the tool
18
  """A tool that connect to an API that provides live football data and compares the stats of two teams in the English Premier League, then it returns a text response
19
+ where you should look for those football teams given, compare stats and provide a reflection on how both stack up.
20
  Args:
21
+ arg1: The first argument provides one of the football teams to check
22
+ arg2: The second football team to check
23
  """
24
  url = "https://free-api-live-football-data.p.rapidapi.com/football-get-standing-home"
25
 
26
+ querystring = {"leagueid": "47"} # British Premier League
27
 
28
  headers = {
29
+ "x-rapidapi-key": rapid_api_key,
30
+ "x-rapidapi-host": "free-api-live-football-data.p.rapidapi.com"
31
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ response = requests.get(url, headers=headers, params=querystring)
34
+ response = response.json()
35
+ tiny_llama= pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto")
36
+
37
+ messages= [
38
+ {
39
+ "role": "system",
40
+ "content": f"You a friendly AI system embedded in a wider AI agent. You are going to faciliate the work of other LLMs. You have received from user an API response in JSON format. In the response item 28 there is a long text starting with a text like 'status:success,response...You are going to extract the team names from the response and compare the stats of the two teams. First team check is {arg1} and second team is {arg2}. Provide a funny reflection on your analysis of how these two teams stack up against each other. You should provide a text response"
41
+ },
42
+ {
43
+ "role": "user",
44
+ "content": response
45
+ }
46
+ ]
47
+ prompt = tiny_llama.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
48
+ insights = tiny_llama(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
49
+
50
+ return insights
51
+
52
 
53
  @tool
54
  def get_current_time_in_timezone(timezone: str) -> str: