File size: 1,134 Bytes
3a9613f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from langchain_community.tools import DuckDuckGoSearchResults, DuckDuckGoSearchRun, tool

@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.")
def search_tool(query: str) -> str:
    print(f"Invoking search tool with query: {query}")
    try:
        search_tool = DuckDuckGoSearchResults(engine="duckduckgo")
        search_results = search_tool.run(query)
        print(f"Search tool returned results: {search_results[:100]}...")  # Print first 100 chars of results
        return search_results
    except Exception as e:
        error_message = f"Error invoking search tool: {e}"
        return error_message

# search_tool = Tool(
#     name = "get_search_results",
#     func = get_search_results,
#     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."
# )


if __name__ == "__main__":
    results = search_tool("Who's the current President of France?")
    print(results)