from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool import datetime import requests import pytz import yaml from tools.final_answer import FinalAnswerTool from Gradio_UI import GradioUI # Below is an example of a tool that does nothing. Amaze us with your creativity ! @tool def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type #Keep this format for the description / args / args description but feel free to modify the tool """A tool that does nothing yet Args: arg1: the first argument arg2: the second argument """ return "What magic will you build ?" @tool def get_country_capital(country_name:str)-> str: """A tool that fetches the country's capital Args: country_name: A string representing the country name """ countries = { "Afghanistan" : "Kabul", "Albania" : "Tirana", "Algeria" : "Algiers", "Andorra" : "Andorra la Vella", "Angola" : "Luanda", "Antigua and Barbuda" : "Saint John’s", "Argentina" : "Buenos Aires", "Armenia" : "Yerevan", "Australia" : "Canberra", "Austria" : "Vienna", "Azerbaijan" : "Baku", "The Bahamas" : "Nassau", "Bahrain" : "Manama", "Bangladesh" : "Dhaka", "Barbados" : "Bridgetown", "Belarus" : "Minsk", "Belgium" : "Brussels", "Belize" : "Belmopan", "Benin" : "Porto-Novo", "Bhutan" : "Thimphu", "Bolivia" : "La Paz, Sucre", "Bosnia and Herzegovina" : "Sarajevo", "Botswana" : "Gaborone", "Brazil" : "Brasilia", "Brunei" : "Bandar Seri Begawan", "Bulgaria" : "Sofia", "Burkina Faso" : "Ouagadougou", "Burundi" : "Bujumbura", "Cambodia" : "Phnom Penh", "Cameroon" : "Yaounde", "Canada" : "Ottawa", "Cape Verde" : "Praia", "Central African Republic" : "Bangui", "Chad" : "N’Djamena", "Chile" : "Santiago", "China" : "Beijing", "Colombia" : "Bogota", "Comoros" : "Moroni", "Republic of the Congo": "Brazzaville", "Democratic Republic of the Congo" : "Kinshasa", "Costa Rica" : "San Jose", "Cote d’Ivoire" : "Yamoussoukro", "Croatia" : "Zagreb", "Cuba" : "Havana", "Cyprus" : "Nicosia", "Czech Republic" : "Prague", "Denmark" : "Copenhagen", "Djibouti" : "Djibouti", "Dominica" : "Roseau", "Dominican Republic" : "Santo Domingo", "East Timor" : "Dili", "Ecuador" : "Quito", "Egypt" : "Cairo", "El Salvador" : "San Salvador", "Equatorial Guinea" : "Malabo", "Eritrea" : "Asmara", "Estonia" : "Tallinn", "Ethiopia" : "Addis Ababa", "Fiji" : "Suva", "Finland" : "Helsinki", "France" : "Paris", "Gabon" : "Libreville", "The Gambia" : "Banjul", "Georgia" : "Tbilisi", "Germany" : "Berlin", "Ghana" : "Accra", "Greece" : "Athens", "Grenada" : "Saint George’s", "Guatemala" : "Guatemala City", "Guinea" : "Conakry", "Guinea-Bissau" : "Bissau", "Guyana" : "Georgetown", "Haiti" : "Port-au-Prince", "Honduras" : "Tegucigalpa", "Hungary" : "Budapest", "Iceland" : "Reykjavik", "India" : "New Delhi", "Indonesia" : "Jakarta", "Iran" : "Tehran", "Iraq" : "Baghdad", "Ireland" : "Dublin", "Israel" : "Jerusalem", "Italy" : "Rome", "Jamaica" : "Kingston", "Japan" : "Tokyo", "Jordan" : "Amman", "Kazakhstan" : "Astana", "Kenya" : "Nairobi", "Kiribati" : "Tarawa Atoll", "North Korea" : "Pyongyang", "South Korea" : "Seoul", "Kosovo" : "Pristina", "Kuwait" : "Kuwait City", "Kyrgyzstan" : "Bishkek", "Laos" : "Vientiane", "Latvia" : "Riga", "Lebanon" : "Beirut", "Lesotho" : "Maseru", "Liberia" : "Monrovia", "Libya" : "Tripoli", "Liechtenstein" : "Vaduz", "Lithuania" : "Vilnius", "Luxembourg" : "Luxembourg", "Macedonia" : "Skopje", "Madagascar" : "Antananarivo", "Malawi" : "Lilongwe", "Malaysia" : "Kuala Lumpur", "Maldives" : "Male", "Mali" : "Bamako", "Malta" : "Valletta", "Marshall Islands" : "Majuro", "Mauritania" : "Nouakchott", "Mauritius" : "Port Louis", "Mexico" : "Mexico City", "Federated States of Micronesia" : "Palikir", "Moldova" : "Chisinau", "Monaco" : "Monaco", "Mongolia" : "Ulaanbaatar", "Montenegro" : "Podgorica", "Morocco" : "Rabat", "Mozambique" : "Maputo", "Myanmar" : "Naypyidaw", "Namibia" : "Windhoek", "Nauru" : "Yaren District", "Nepal" : "Kathmandu", "Netherlands" : "Amsterdam", "New Zealand" : "Wellington", "Nicaragua" : "Managua", "Niger" : "Niamey", "Nigeria" : "Abuja", "Norway" : "Oslo", "Oman" : "Muscat", "Pakistan" : "Islamabad", "Palau" : "Melekeok", "Panama" : "Panama City", "Papua New Guinea" : "Port Moresby", "Paraguay" : "Asuncion", "Peru" : "Lima", "Philippines" : "Manila", "Poland" : "Warsaw", "Portugal" : "Lisbon", "Qatar" : "Doha", "Romania" : "Bucharest", "Russia" : "Moscow", "Rwanda" : "Kigali", "Saint Kitts and Nevis" : "Basseterre", "Saint Lucia" : "Castries", "Saint Vincent and the Grenadines" : "Kingstown", "Samoa" : "Apia", "San Marino" : "San Marino", "Sao Tome and Principe" : "Sao Tome", "Saudi Arabia" : "Riyadh", "Senegal" : "Dakar", "Serbia" : "Belgrade", "Seychelles" : "Victoria", "Sierra Leone" : "Freetown", "Singapore" : "Singapore", "Slovakia" : "Bratislava", "Slovenia" : "Ljubljana", "Solomon Islands" : "Honiara", "Somalia" : "Mogadishu", "South Africa" : "Pretoria, Cape Town, Bloemfontein", "South Sudan" : "Juba", "Spain" : "Madrid", "Sri Lanka" : "Colombo, Sri Jayewardenepura Kotte", "Sudan" : "Khartoum", "Suriname" : "Paramaribo", "Swaziland" : "Mbabane", "Sweden" : "Stockholm", "Switzerland" : "Bern", "Syria" : "Damascus", "Taiwan" : "Taipei", "Tajikistan" : "Dushanbe", "Tanzania" : "Dodoma", "Thailand" : "Bangkok", "Togo" : "Lome", "Tonga" : "Nuku’alofa", "Trinidad and Tobago" : "Port-of-Spain", "Tunisia" : "Tunis", "Turkey" : "Ankara", "Turkmenistan" : "Ashgabat", "Tuvalu" : "Funafuti", "Uganda" : "Kampala", "Ukraine" : "Kyiv", "United Arab Emirates" : "Abu Dhabi", "United Kingdom" : "London", "United States of America" : "Washington D.C.", "Uruguay" : "Montevideo", "Uzbekistan" : "Tashkent", "Vanuatu" : "Port-Vila", "Vatican City" : "Vatican City", "Venezuela" : "Caracas", "Vietnam" : "Hanoi", "Yemen" : "Sanaa", "Zambia" : "Lusaka", "Zimbabwe" : "Harare" } capital = countries.get(country_name) if not capital: return f"Cannot find the capital of {country_name} Try to enter the name correct" return f"The Capital of {country_name} is {capital}" @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)}" final_answer = FinalAnswerTool() # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder: # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' model = HfApiModel( max_tokens=2096, temperature=0.5, model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded custom_role_conversions=None, ) # Import tool from Hub image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) agent = CodeAgent( model=model, tools=[final_answer], ## add your tools here (don't remove final answer) max_steps=6, verbosity_level=1, grammar=None, planning_interval=None, name=None, description=None, prompt_templates=prompt_templates ) GradioUI(agent).launch()