mjschock commited on
Commit
ea0c151
·
unverified ·
1 Parent(s): a3a55bb

Add main function to tool.py for direct execution of SmartSearchTool. Implement logging and command-line argument handling for search queries, enhancing usability and testing capabilities.

Browse files
Files changed (1) hide show
  1. tools/smart_search/tool.py +40 -0
tools/smart_search/tool.py CHANGED
@@ -55,3 +55,43 @@ class SmartSearchTool(Tool):
55
  # If no Wikipedia link was found or Wikipedia search failed, return the web search result
56
  logger.info("Returning web search result only")
57
  return f"Web search result:\n{web_result}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  # If no Wikipedia link was found or Wikipedia search failed, return the web search result
56
  logger.info("Returning web search result only")
57
  return f"Web search result:\n{web_result}"
58
+
59
+
60
+ def main(query: str) -> str:
61
+ """
62
+ Test function to run the SmartSearchTool directly.
63
+
64
+ Args:
65
+ query: The search query to test
66
+
67
+ Returns:
68
+ The search results
69
+ """
70
+ # Configure logging
71
+ logging.basicConfig(
72
+ level=logging.INFO,
73
+ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
74
+ )
75
+
76
+ # Create and run the tool
77
+ tool = SmartSearchTool()
78
+ result = tool.forward(query)
79
+
80
+ # Print the result
81
+ print("\nSearch Results:")
82
+ print("-" * 80)
83
+ print(result)
84
+ print("-" * 80)
85
+
86
+ return result
87
+
88
+
89
+ if __name__ == "__main__":
90
+ import sys
91
+
92
+ if len(sys.argv) > 1:
93
+ query = " ".join(sys.argv[1:])
94
+ main(query)
95
+ else:
96
+ print("Usage: python tool.py <search query>")
97
+ print("Example: python tool.py 'Mercedes Sosa discography'")