robertgil commited on
Commit
56c4b64
·
verified ·
1 Parent(s): 516d9c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -5,6 +5,7 @@ import requests
5
  import pytz
6
  import yaml
7
  import os
 
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
@@ -12,11 +13,22 @@ from Gradio_UI import GradioUI
12
  rapid_api_key=os.environ["RAPID_KEY"]
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
@@ -37,7 +49,7 @@ def get_football_results(arg1: str, arg2: str) -> str: # it's import to specify
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",
@@ -45,9 +57,9 @@ def get_football_results(arg1: str, arg2: str) -> str: # it's import to specify
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[0]["generated_text"]
51
 
52
 
53
  @tool
@@ -88,7 +100,7 @@ with open("prompts.yaml", 'r') as stream:
88
 
89
  agent = CodeAgent(
90
  model=model,
91
- tools=[final_answer, get_current_time_in_timezone, get_football_results], ## add your tools here (don't remove final answer)
92
  max_steps=6,
93
  verbosity_level=1,
94
  grammar=None,
 
5
  import pytz
6
  import yaml
7
  import os
8
+ import torch
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
 
13
  rapid_api_key=os.environ["RAPID_KEY"]
14
 
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
+ #@tool
17
+ #def reflecting_on_results(arg1: str) -> str:
18
+ # """A tool that receives the football teams comparison and then it reflects on the results with an insightful comment, it could be funny or witty
19
+ # Args:
20
+ # arg1: The first argument receives a string with the comparison of two teams as queried by user
21
+ # """
22
+ # insights
23
+ # return insights
24
+
25
+
26
+
27
  @tool
28
  def get_football_results(arg1: str, arg2: str) -> str: # it's import to specify the return type
29
  # Keep this format for the description / args / args description but feel free to modify the tool
30
  """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
31
+ where you should look for those football teams given, returns a comparison of stats including a funny reflection on the comparison.
32
  Args:
33
  arg1: The first argument provides one of the football teams to check
34
  arg2: The second football team to check
 
49
  messages= [
50
  {
51
  "role": "system",
52
+ "content": f"You are 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"
53
  },
54
  {
55
  "role": "user",
 
57
  }
58
  ]
59
  prompt = tiny_llama.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
60
+ comparison = tiny_llama(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
61
 
62
+ return comparison[0]["generated_text"]
63
 
64
 
65
  @tool
 
100
 
101
  agent = CodeAgent(
102
  model=model,
103
+ tools=[final_answer, get_current_time_in_timezone, get_football_results, reflecting_on_results] ## add your tools here (don't remove final answer)
104
  max_steps=6,
105
  verbosity_level=1,
106
  grammar=None,