kasn-code/First_agent_template
0
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6import platform7from tools.final_answer import FinalAnswerTool8 9from Gradio_UI import GradioUI10 11# Below is an example of a tool that does nothing. Amaze us with your creativity !12@tool13def my_virtual_house()-> str: #it's import to specify the return type14 """A tool that tells in what house you live in. 15 """16 return platform.system()17 18@tool19def get_current_time_in_timezone(timezone: str) -> str:20 """A tool that fetches the current local time in a specified timezone.21 Args:22 timezone: A string representing a valid timezone (e.g., 'America/New_York').23 """24 try:25 # Create timezone object26 tz = pytz.timezone(timezone)27 # Get current time in that timezone28 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")29 return f"The current local time in {timezone} is: {local_time}"30 except Exception as e:31 return f"Error fetching time for timezone '{timezone}': {str(e)}"32 33 34final_answer = FinalAnswerTool()35model = HfApiModel(36max_tokens=2096,37temperature=0.5,38model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',# it is possible that this model may be overloaded39custom_role_conversions=None,40)41 42 43# Import tool from Hub44image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)45 46with open("prompts.yaml", 'r') as stream:47 prompt_templates = yaml.safe_load(stream)48 49agent = CodeAgent(50 model=model,51 tools=[final_answer,image_generation_tool,my_virtual_house], ## add your tools here (don't remove final answer)52 max_steps=6,53 verbosity_level=1,54 grammar=None,55 planning_interval=None,56 name=None,57 description=None,58 prompt_templates=prompt_templates59)60 61 62GradioUI(agent).launch()