Update agent/tools/search_tool.py
Browse files- agent/tools/search_tool.py +24 -25
agent/tools/search_tool.py
CHANGED
|
@@ -1,25 +1,24 @@
|
|
| 1 |
-
from langchain_community.tools import DuckDuckGoSearchResults, DuckDuckGoSearchRun,
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
#
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
print(results)
|
|
|
|
| 1 |
+
from langchain_community.tools import DuckDuckGoSearchResults, DuckDuckGoSearchRun, tool
|
| 2 |
+
|
| 3 |
+
@tool(description="Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results.")
|
| 4 |
+
def search_tool(query: str) -> str:
|
| 5 |
+
print(f"Invoking search tool with query: {query}")
|
| 6 |
+
try:
|
| 7 |
+
search_tool = DuckDuckGoSearchResults(engine="duckduckgo")
|
| 8 |
+
search_results = search_tool.run(query)
|
| 9 |
+
print(f"Search tool returned results: {search_results[:100]}...") # Print first 100 chars of results
|
| 10 |
+
return search_results
|
| 11 |
+
except Exception as e:
|
| 12 |
+
error_message = f"Error invoking search tool: {e}"
|
| 13 |
+
return error_message
|
| 14 |
+
|
| 15 |
+
# search_tool = Tool(
|
| 16 |
+
# name = "get_search_results",
|
| 17 |
+
# func = get_search_results,
|
| 18 |
+
# description = "Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results."
|
| 19 |
+
# )
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
results = search_tool("Who's the current President of France?")
|
| 24 |
+
print(results)
|
|
|