mo-ali-nlp commited on
Commit
2da0c66
·
verified ·
1 Parent(s): 6be8b61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -19,19 +19,20 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
19
  return "What magic will you build ?"
20
 
21
  @tool
22
- def get_news_headlines(headlines: str) -> str:
23
- """A tool that fetches the three most recent headlines from the news.
 
24
  Args:
25
- headlines: A string representing the latest three news headlines.
26
  """
27
  try:
28
  hl = DuckDuckGoSearchTool()
29
- results = hl.run(f"{headlines} news")
30
- return f"The three most recent news headlines from the news are {results}."
 
31
  except Exception as e:
32
- import traceback
33
- traceback.print_exc() # dumps full stack to your logs
34
- return f"Error fetching the news headlines: {e}."
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
 
19
  return "What magic will you build ?"
20
 
21
  @tool
22
+ def get_news_headlines(topic: str = "latest") -> str:
23
+ """Fetches the three most recent news headlines for a given topic.
24
+
25
  Args:
26
+ topic: The subject to search headlines for (defaults to "latest").
27
  """
28
  try:
29
  hl = DuckDuckGoSearchTool()
30
+ results = hl.run(f"{topic} news")
31
+ headlines = results[:3] if isinstance(results, list) else results.split("\n")[:3]
32
+ return "\n".join(f"{i+1}. {h}" for i, h in enumerate(headlines))
33
  except Exception as e:
34
+ import traceback; traceback.print_exc()
35
+ return f"Error fetching news headlines: {e}"
 
36
 
37
  @tool
38
  def get_current_time_in_timezone(timezone: str) -> str: