NatalieCheong commited on
Commit
ad7a2ed
·
verified ·
1 Parent(s): 8502d9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -34
app.py CHANGED
@@ -10,46 +10,34 @@ from Gradio_UI import GradioUI
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  # Replace this part in app.py
12
  @tool
13
- def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
14
- """A tool that combines web search and optional image generation
15
  Args:
16
- search_query: The search query to look up
17
- generate_image: Whether to also generate an image based on the search results
18
  """
19
  try:
20
- # First try to create the search tool
21
- print("Attempting to create DuckDuckGoSearchTool...")
22
- search_tool = None
23
- try:
24
- search_tool = DuckDuckGoSearchTool()
25
- print("Successfully created DuckDuckGoSearchTool")
26
- except Exception as search_tool_error:
27
- return f"Failed to create search tool: {str(search_tool_error)}"
28
-
29
- # Then try to perform the search
30
- print(f"Attempting search for: {search_query}")
31
- try:
32
- results = search_tool(search_query)
33
- print(f"Search completed with {len(results) if results else 0} results")
34
- except Exception as search_error:
35
- return f"Failed to perform search: {str(search_error)}"
36
-
37
- # Process the results
38
  if not results:
39
- return "Search completed but no results found."
40
-
41
- first_result = results[0]
42
- result_text = (
43
- f"Here are the latest findings about artificial intelligence:\n\n"
44
- f"Title: {first_result.get('title', 'No title available')}\n"
45
- f"Summary: {first_result.get('snippet', 'No summary available')}"
46
- )
 
 
 
 
 
47
 
48
- print("Successfully created result text")
49
- return result_text
50
-
51
  except Exception as e:
52
- return f"Unexpected error in my_custom_tool: {str(e)}"
53
 
54
 
55
  @tool
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  # Replace this part in app.py
12
  @tool
13
+ def my_custom_tool(topic: str, include_links: bool = False) -> str:
14
+ """A tool that fetches comprehensive information about any topic using DuckDuckGo search
15
  Args:
16
+ topic: The topic to search for information about
17
+ include_links: Whether to include source links in the response (default: False)
18
  """
19
  try:
20
+ print(f"Searching for information about: {topic}")
21
+ search_tool = DuckDuckGoSearchTool()
22
+ results = search_tool(topic)
23
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  if not results:
25
+ return f"No information found about {topic}"
26
+
27
+ # Get the top 3 results for more comprehensive information
28
+ summary = f"Here's what I found about {topic}:\n\n"
29
+
30
+ for i, result in enumerate(results[:3], 1):
31
+ summary += f"{i}. {result['title']}\n"
32
+ summary += f"{result['snippet']}\n"
33
+ if include_links:
34
+ summary += f"Source: {result['link']}\n"
35
+ summary += "\n"
36
+
37
+ return summary.strip()
38
 
 
 
 
39
  except Exception as e:
40
+ return f"Error while searching: {str(e)}"
41
 
42
 
43
  @tool