manuvats commited on
Commit
c663acc
·
verified ·
1 Parent(s): ae7a494

Added get_latest_news tool

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -18,6 +18,30 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
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 +79,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,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_latest_news(topic: str) -> str:
23
+ """Get the latest news about a topic
24
+ Args:
25
+ topic: Name of the topic
26
+ """
27
+ try:
28
+
29
+ search_tool = DuckDuckGoSearchTool(max_results=10)
30
+ results = search_tool.forward(
31
+ f"""Get the latest news on {topic}"""
32
+ )
33
+
34
+ if results:
35
+ top_result = results[0] # Assuming results is a list
36
+ return top_result
37
+ else:
38
+ return "No results found."
39
+ except requests.exceptions.RequestException as e:
40
+ return f"Error: Failed to fetch image: {str(e)}"
41
+ except Exception as e:
42
+ return f"Error: An unexpected error occurred: {str(e)}"
43
+
44
+
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
47
  """A tool that fetches the current local time in a specified timezone.
 
79
 
80
  agent = CodeAgent(
81
  model=model,
82
+ tools=[final_answer, get_latest_news, get_current_time_in_timezone]], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,