add tavily_search
Browse files1123412 unmodified lines17181920202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667from smolagents import DuckDuckGoSearchTool, Toolfrom smolagents import DuckDuckGoSearchTool, Tool,toolimport wikipediaapi
class WikipediaSearchTool(Tool):12 unmodified lines return "No Wikipedia page found." return page.summary[:1000]
my_tool_list = [WikipediaSearchTool(),DuckDuckGoSearchTool()]@tooldef tavily_search(query: str) -> str: """ Search the web using Tavily API Args: query: The search query Returns: Search results as formatted text """ api_key = os.getenv("TAVILY_API_KEY") if not api_key: return "Tavily API key not found" url = "https://api.tavily.com/search" payload = { "api_key": api_key, "query": query, "search_depth": "basic", "include_answer": True, "include_domains": [], "exclude_domains": [], "max_results": 5 } try: response = requests.post(url, json=payload, timeout=10) response.raise_for_status() data = response.json() results = [] if data.get("answer"): results.append(f"Quick Answer: {data['answer']}") for result in data.get("results", [])[:3]: results.append(f"Title: {result.get('title', 'N/A')}") results.append(f"URL: {result.get('url', 'N/A')}") results.append(f"Content: {result.get('content', 'N/A')[:200]}...") results.append("---") return "\n".join(results) except Exception as e: return f"Tavily search error: {str(e)}"
my_tool_list = [ WikipediaSearchTool(), DuckDuckGoSearchTool() tavily_search,]my_tools.py+49-2