Gabandino commited on
Commit
32eae92
·
verified ·
1 Parent(s): 29e0a1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -29
app.py CHANGED
@@ -50,38 +50,19 @@ def search_news_headlines(source: str) -> str:
50
 
51
  # Use existing DuckDuckGoSearchTool implementation
52
  ddg_tool = DuckDuckGoSearchTool(max_results=5)
53
- results = ddg_tool.forward(search_query)
54
 
55
- return f"Recent news from {source}:\n{results}"
 
 
 
 
 
 
 
56
 
57
  except Exception as e:
58
  return f"News search failed: {str(e)}"
59
-
60
-
61
- @tool
62
- def get_current_time_in_timezone(timezone: str) -> str:
63
- """Fetches the current local time in a specified timezone and provides a human-friendly description.
64
-
65
- Args:
66
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
67
-
68
- Returns:
69
- A dictionary containing the raw datetime string and a human-readable message.
70
- """
71
- try:
72
- tz = pytz.timezone(timezone)
73
- local_time = datetime.datetime.now(tz)
74
- formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
75
-
76
- response = {
77
- "datetime": formatted_time,
78
- "message": f"The current local time in {timezone.replace('_', ' ')} is {formatted_time}."
79
- }
80
- return response["message"]
81
-
82
- except Exception as e:
83
- return {"error": f"Error fetching time for timezone '{timezone}': {str(e)}"}
84
-
85
 
86
 
87
  final_answer = FinalAnswerTool()
@@ -102,7 +83,7 @@ agent = CodeAgent(
102
  model=model,
103
  tools=[final_answer, search_news_headlines], ## add your tools here (don't remove final answer)
104
  max_steps=6,
105
- verbosity_level=0,
106
  grammar=None,
107
  planning_interval=None,
108
  name=None,
 
50
 
51
  # Use existing DuckDuckGoSearchTool implementation
52
  ddg_tool = DuckDuckGoSearchTool(max_results=5)
53
+ raw_results = ddg_tool.forward(search_query)
54
 
55
+ # Parse the raw results to extract titles and links
56
+ # DuckDuckGo results come in markdown format: [title](link)
57
+ import re
58
+ headlines = re.findall(r'\[(.*?)\]\((.*?)\)', raw_results)
59
+
60
+ # Format the results
61
+ formatted_headlines = [f"{i+1}. {title} {link}" for i, (title, link) in enumerate(headlines[:5])]
62
+ return f"Here are the latest news from {source}:\n\n" + "\n".join(formatted_headlines)
63
 
64
  except Exception as e:
65
  return f"News search failed: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
 
68
  final_answer = FinalAnswerTool()
 
83
  model=model,
84
  tools=[final_answer, search_news_headlines], ## add your tools here (don't remove final answer)
85
  max_steps=6,
86
+ verbosity_level=1,
87
  grammar=None,
88
  planning_interval=None,
89
  name=None,