Mahdimtd commited on
Commit
eafd2f6
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -7
app.py CHANGED
@@ -4,19 +4,49 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  from Gradio_UI import GradioUI
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
+ from tavily import TavilyClient
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def search_internet(query: str) -> str:
13
+ """Search the internet using Tavily API to retrieve relevant results for a given query.
14
+
15
  Args:
16
+ query: The search query string to look up information about.
 
17
  """
18
+ print(f"🔍 Searching with Tavily: {query}")
19
+
20
+ # Get API key from tavily.com (1000 free searches/month)
21
+ api_key = "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"
22
+
23
+ try:
24
+ client = TavilyClient(api_key=api_key)
25
+
26
+ response = client.search(
27
+ query=query,
28
+ max_results=3
29
+ )
30
+
31
+ results = response.get('results', [])
32
+
33
+ if not results:
34
+ return "No results found."
35
+
36
+ output = []
37
+ for i, result in enumerate(results, 1):
38
+ title = result.get('title', 'No title')
39
+ content = result.get('content', 'No description')
40
+ url = result.get('url', '')
41
+ output.append(f"{i}. {title}\n{content[:200]}...\nSource: {url}\n")
42
+
43
+ return "\n".join(output)
44
+
45
+ except Exception as e:
46
+ return f"Search error: {str(e)}"
47
+
48
+
49
+
50
 
51
  @tool
52
  def get_current_time_in_timezone(timezone: str) -> str: