from typing import List, Optional from tavily import TavilyClient from langchain_core.tools import tool import time client =TavilyClient('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') def search(query: str, topic: Optional[str] = None, max_results: int = 5) -> List[str]: """ Perform a Tavily search and return only the extracted content from results. Args: query (str): The search query string. topic (Optional[str]): (Optional) Topic/domain to refine the search. max_results (int): Maximum number of search results to retrieve. Returns: List[str]: A list of content snippets extracted from the search results. """ try: response = client.search( query=query, topic=topic, max_results=max_results, search_depth="advanced", ) # Extract only "content" fields safely contents = [ result.get("content", "").strip() for result in response.get("results", []) if result.get("content") ] return contents if contents else ["No content found."] except Exception as e: return [f"Search failed: {str(e)}"] def get_time(): return time.time() print(get_time())