Louis-bou commited on
Commit
33b84b9
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -18,6 +18,25 @@ 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 +74,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,
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+
22
+ @tool
23
+ def web_search_DDG(query:str)-> str:
24
+ """A tool uses DuckuckGo to fetch the web to answer the query.
25
+ Args:
26
+ query: the web query to bee looked up (e.g. "Who is Clovis?")
27
+ """
28
+
29
+ try:
30
+ search_tool = DuckDuckGoSearchTool()
31
+ results = search_tool(query)
32
+ if not results or "No results found" in results:
33
+ return f"No answer was found to the request '{query}'. Please reformulate."
34
+ return f"The answer for the question '{query}' is:\n\n{results}"
35
+ except Exception as e:
36
+ return f"An unexpected issue occurred: {str(e)}"
37
+
38
+ return "What magic will you build ?"
39
+
40
  @tool
41
  def get_current_time_in_timezone(timezone: str) -> str:
42
  """A tool that fetches the current local time in a specified timezone.
 
74
 
75
  agent = CodeAgent(
76
  model=model,
77
+ tools=[final_answer, research_tool], ## add your tools here (don't remove final answer)
78
  max_steps=6,
79
  verbosity_level=1,
80
  grammar=None,