nicolasTch commited on
Commit
19fb71c
·
verified ·
1 Parent(s): ae7a494
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -7,17 +7,48 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -55,7 +86,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,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def get_top_headlines(country:str=None, category:str=None)-> str:
12
+ """
13
+ Fetch the current top headlines for a given country, category, or source.
14
+
15
  Args:
16
+ country: The country code (e.g., 'us' for United States).
17
+ category: The category (e.g., 'business', 'sports', 'technology').
18
+
19
+ Returns:
20
+ list: A list of top headlines with title, description, and URL.
21
  """
22
+ url = "https://newsapi.org/v2/top-headlines"
23
+ params = {
24
+ "apiKey": "877ba42b026143dcbdcb59b6c2b64c1e",
25
+ }
26
+
27
 
28
+ if country:
29
+ params["country"] = country
30
+ if category:
31
+ params["category"] = category
32
+
33
+ response = requests.get(url, params=params)
34
+
35
+ if response.status_code == 200:
36
+ data = response.json()
37
+ if data["status"] == "ok":
38
+ articles = data["articles"]
39
+ if not articles:
40
+ return "No headlines found."
41
+
42
+ result = "\n".join([
43
+ f"{idx + 1}. {article['title']}\n {article['description']}\n {article['url']}\n"
44
+ for idx, article in enumerate(articles)
45
+ ])
46
+ return result
47
+ else:
48
+ return "Failed to fetch news."
49
+ else:
50
+ return f"Request failed with status code {response.status_code}"
51
+
52
  @tool
53
  def get_current_time_in_timezone(timezone: str) -> str:
54
  """A tool that fetches the current local time in a specified timezone.
 
86
 
87
  agent = CodeAgent(
88
  model=model,
89
+ tools=[get_top_headlines, final_answer], ## add your tools here (don't remove final answer)
90
  max_steps=6,
91
  verbosity_level=1,
92
  grammar=None,