k0smes commited on
Commit
c70fc0e
·
verified ·
1 Parent(s): c7db478

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -20,6 +20,32 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
20
  """
21
  return "What magic will you build ?"
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  @tool
24
  def get_current_time_in_timezone(timezone: str) -> str:
25
  """A tool that fetches the current local time in a specified timezone.
 
20
  """
21
  return "What magic will you build ?"
22
 
23
+
24
+ @tool
25
+ def web_search(query: str) -> str:
26
+ """Search the web using DuckDuckGo and return relevant results.
27
+ Args:
28
+ query: A search query to look up on the web.
29
+ """
30
+ try:
31
+ from ddgs import DDGS
32
+
33
+ results = []
34
+ with DDGS() as ddgs:
35
+ for r in ddgs.text(query, max_results=5):
36
+ title = r.get("title", "")
37
+ body = r.get("body", "")
38
+ url = r.get("href", "")
39
+ results.append(f"- {title}\n {body}\n {url}")
40
+
41
+ if not results:
42
+ return "No search results found."
43
+
44
+ return "\n".join(results)
45
+
46
+ except Exception as e:
47
+ return f"Web search failed: {str(e)}"
48
+
49
  @tool
50
  def get_current_time_in_timezone(timezone: str) -> str:
51
  """A tool that fetches the current local time in a specified timezone.