import asyncio import os import sys import logging import random import pandas as pd import requests import wikipedia as wiki from markdownify import markdownify as to_markdown from typing import Any from dotenv import load_dotenv from smolagents import InferenceClientModel, LiteLLMModel, CodeAgent, ToolCallingAgent, Tool, DuckDuckGoSearchTool load_dotenv() class MathSolverTool(Tool): name="MathSolver" description="A tool to solve mathematical problems." inputs={"input":{"type":"string", "description":"The mathematical problem to solve."}} output_type="string" def forward(self,input:str): try: return str(eval(input, {"__builtins__": {}})) except Exception as e: return f"Math error: {e}" class WikiTitleFinder(Tool): name = "wiki_titles" description = "Search for related Wikipedia page titles." inputs = {"query": {"type": "string", "description": "Search query."}} output_type = "string" def forward(self, query: str) -> str: results = wiki.search(query) return ", ".join(results) if results else "No results." class WikiContentFetcher(Tool): name = "wiki_page" description = "Fetch Wikipedia page content." inputs = {"page_title": {"type": "string", "description": "Wikipedia page title."}} output_type = "string" def forward(self, page_title: str) -> str: try: return to_markdown(wiki.page(page_title).html()) except wiki.exceptions.PageError: return f"'{page_title}' not found."