AC-Angelo93 commited on
Commit
d9a0ba7
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -26
app.py CHANGED
@@ -7,31 +7,47 @@ 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.
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
 
26
  """
27
  try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
33
- except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  final_answer = FinalAnswerTool()
@@ -46,16 +62,14 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
46
  custom_role_conversions=None,
47
  )
48
 
49
-
50
- # Import tool from Hub
51
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
-
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(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
+ # Below is my news aggregator tool!
11
  @tool
12
+ def news_aggregator(keyword: str, max_results: int = 5) -> str:
 
 
 
 
 
13
  """
14
+ A tool that fetches the latest news articles related to a specific keyword.
15
+
 
 
 
16
  Args:
17
+ keyword: The topic or keyword to search for (e.g., "AI", "technology").
18
+ max_results: The maximum number of articles to return (default is 5).
19
+
20
+ Returns:
21
+ A string containing the titles and URLs of the latest news articles.
22
  """
23
  try:
24
+ # I am using the NewsAPI key
25
+ api_key = "d43565ac0e674145a22c5f0de4dcd69c"
26
+ url = f"https://newsapi.org/v2/everything?q={keyword}&pageSize={max_results}&apiKey={api_key}"
27
+
28
+ # Make the API request
29
+ response = requests.get(url)
30
+ response.raise_for_status() # Raise an error for bad status codes
31
+
32
+ # Parse the JSON response
33
+ data = response.json()
34
+
35
+ # Extract relevant information (titles and URLs)
36
+ articles = data.get("articles", [])
37
+ if not articles:
38
+ return "No news articles found for the given keyword."
39
+
40
+ # Format the results
41
+ result = "Here are the latest news articles:\n"
42
+ for i, article in enumerate(articles, 1):
43
+ title = article.get("title", "No title")
44
+ url = article.get("url", "#")
45
+ result += f"{i}. {title}\n {url}\n"
46
+
47
+ return result
48
+
49
+ except requests.exceptions.RequestException as e:
50
+ return f"Error fetching news articles: {str(e)}"
51
 
52
 
53
  final_answer = FinalAnswerTool()
 
62
  custom_role_conversions=None,
63
  )
64
 
65
+ # prompt templates
 
 
 
66
  with open("prompts.yaml", 'r') as stream:
67
  prompt_templates = yaml.safe_load(stream)
68
+
69
+ # Agent and tools
70
  agent = CodeAgent(
71
  model=model,
72
+ tools=[final_answer, news_aggregator], ## add your tools here (don't remove final answer)
73
  max_steps=6,
74
  verbosity_level=1,
75
  grammar=None,