import datetime import pytz import wikipedia from smolagents import tool @tool def search_wikipedia(search_term:str)-> list[tuple[str, str]]: """A tool that searches for wikipedia articles. Args: search_term: The search term to use. Returns: list[tuple[str, str]]: A list of 2-tuples with the title and summary of the content. """ search_results_with_summary = [] for result in wikipedia.search(search_term): try: search_results_with_summary.append((result, wikipedia.summary(result))) except wikipedia.exceptions.PageError: continue return search_results_with_summary @tool def get_wikipedia_article_content(page_title: str) -> str: """A tool that gets the content of a wikipedia article. Args: page_title: The title of the article. Returns: str: The content of the wikipedia article. """ return wikipedia.page(page_title).content @tool def get_current_time_in_timezone(timezone: str) -> str: """A tool that fetches the current local time in a specified timezone. Args: timezone: A string representing a valid timezone (e.g., 'America/New_York'). """ try: # Create timezone object tz = pytz.timezone(timezone) # Get current time in that timezone local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S") return f"The current local time in {timezone} is: {local_time}" except Exception as e: return f"Error fetching time for timezone '{timezone}': {str(e)}"