NatalieCheong commited on
Commit
49c0f04
·
verified ·
1 Parent(s): 616c5b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -16,16 +16,19 @@ def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
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
- print("my_custom_tool called with query:", search_query) # Debug print
 
20
 
21
  try:
22
  # Initialize the search tool
 
23
  search_tool = DuckDuckGoSearchTool()
24
- print("DuckDuckGoSearchTool initialized") # Debug print
25
 
26
  # Perform the search
 
27
  results = search_tool(search_query)
28
- print(f"Search returned {len(results) if results else 0} results") # Debug print
 
29
 
30
  if not results:
31
  return "No results found for the query."
@@ -33,13 +36,24 @@ def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
33
  # Get the first result
34
  first_result = results[0]
35
 
36
- # Use final_answer to return the result
37
- result_text = f"Latest AI News:\n{first_result['title']}\n{first_result['snippet']}"
 
 
 
 
 
 
 
 
38
  return result_text
39
 
40
  except Exception as e:
41
- error_message = f"Error in my_custom_tool: {str(e)}"
42
- print(error_message) # Debug print
 
 
 
43
  return error_message
44
 
45
 
 
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
+ print("\n=== DEBUG: my_custom_tool started ===")
20
+ print(f"Received query: {search_query}")
21
 
22
  try:
23
  # Initialize the search tool
24
+ print("Initializing DuckDuckGoSearchTool...")
25
  search_tool = DuckDuckGoSearchTool()
 
26
 
27
  # Perform the search
28
+ print("Performing search...")
29
  results = search_tool(search_query)
30
+
31
+ print(f"Search complete. Got {len(results) if results else 0} results")
32
 
33
  if not results:
34
  return "No results found for the query."
 
36
  # Get the first result
37
  first_result = results[0]
38
 
39
+ # Create formatted result
40
+ result_text = (
41
+ f"Latest AI News:\n"
42
+ f"Title: {first_result['title']}\n"
43
+ f"Summary: {first_result['snippet']}"
44
+ )
45
+
46
+ print("Successfully created result text")
47
+ print("=== DEBUG: my_custom_tool completed ===\n")
48
+
49
  return result_text
50
 
51
  except Exception as e:
52
+ error_message = f"ERROR in my_custom_tool: {str(e)}\n"
53
+ error_message += f"Error type: {type(e)}\n"
54
+ error_message += f"Error location: {e.__traceback__.tb_frame.f_code.co_filename}, line {e.__traceback__.tb_lineno}"
55
+ print(error_message)
56
+ print("=== DEBUG: my_custom_tool failed ===\n")
57
  return error_message
58
 
59