fercucci/First_agent_template
0
1from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7 8from Gradio_UI import GradioUI9 10@tool11def my_custom_tool(arg1:str, arg2:int)-> str:12 """A tool that repeats a string an specific amount of times13 Args:14 arg1: the string15 arg2: the number of repetitions16 """17 return arg1 * arg218 19@tool20def get_current_time_in_timezone(timezone: str) -> str:21 """A tool that fetches the current local time in a specified timezone.22 Args:23 timezone: A string representing a valid timezone (e.g., 'America/New_York').24 """25 try:26 # Create timezone object27 tz = pytz.timezone(timezone)28 # Get current time in that timezone29 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")30 return f"The current local time in {timezone} is: {local_time}"31 except Exception as e:32 return f"Error fetching time for timezone '{timezone}': {str(e)}"33 34 35final_answer = FinalAnswerTool()36model = HfApiModel(37max_tokens=2096,38temperature=0.5,39model_id='Qwen/Qwen2.5-Coder-32B-Instruct',40custom_role_conversions=None,41)42 43 44# Import tool from Hub45image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)46 47with open("prompts.yaml", 'r') as stream:48 prompt_templates = yaml.safe_load(stream)49 50agent = CodeAgent(51 model=model,52 tools=[my_custom_tool, final_answer], # add your tools here (don't remove final_answer)53 max_steps=6,54 verbosity_level=1,55 grammar=None,56 planning_interval=None,57 name=None,58 description=None,59 prompt_templates=prompt_templates60)61 62 63GradioUI(agent).launch()