zBotta commited on
Commit
3a9613f
·
verified ·
1 Parent(s): 195cc35

Update agent/tools/search_tool.py

Browse files
Files changed (1) hide show
  1. 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, BingSearchResults, BingSearchRun
2
- from langchain.tools import tool
3
-
4
- @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.")
5
- def search_tool(query: str) -> str:
6
- print(f"Invoking search tool with query: {query}")
7
- try:
8
- search_tool = DuckDuckGoSearchResults(engine="duckduckgo")
9
- search_results = search_tool.run(query)
10
- print(f"Search tool returned results: {search_results[:100]}...") # Print first 100 chars of results
11
- return search_results
12
- except Exception as e:
13
- error_message = f"Error invoking search tool: {e}"
14
- return error_message
15
-
16
- # search_tool = Tool(
17
- # name = "get_search_results",
18
- # func = get_search_results,
19
- # 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."
20
- # )
21
-
22
-
23
- if __name__ == "__main__":
24
- results = search_tool("Who's the current President of France?")
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)