sahilsd/First_agent_template
0
1from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7from Gradio_UI import GradioUI8 9@tool10def my_custom_tool(arg1:str, arg2:int) -> str:11 """A tool that does nothing yet.12 Args:13 arg1: the first argument14 arg2: the second argument15 """16 return "What magic will you build?"17 18@tool19def get_current_time_in_timezone(timezone: str) -> str:20 """Fetches the current local time in a given timezone.21 22 Args:23 timezone (str): The name of the timezone to fetch the current time for (e.g., 'America/New_York').24 25 Returns:26 str: A string containing the local time information.27 """28 try:29 tz = pytz.timezone(timezone)30 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")31 return f"The current local time in {timezone} is: {local_time}"32 except Exception as e:33 return f"Error fetching time: {str(e)}"34 35 36final_answer = FinalAnswerTool()37model = HfApiModel(38 max_tokens=2096,39 temperature=0.5,40 model_id='Qwen/Qwen2.5-Coder-32B-Instruct',41)42 43# Load system prompts correctly44with open("prompts.yaml", 'r') as stream:45 prompts = yaml.safe_load(stream)46 47# Fix prompt_templates with required fields48prompt_templates = {49 "system_prompt": prompts["system_prompt"],50 "planning": prompts["planning"],51 "managed_agent": prompts["managed_agent"],52 "final_answer": "Return the final answer clearly and concisely to the user.",53}54 55# Initialize Agent56agent = CodeAgent(57 model=model,58 tools=[final_answer, my_custom_tool, get_current_time_in_timezone], # add your other tools too!59 max_steps=6,60 verbosity_level=1,61 grammar=None,62 planning_interval=None,63 name=None,64 description=None,65 prompt_templates=prompt_templates66)67 68GradioUI(agent).launch()69 