AliceChem/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# Below is an example of a tool that does nothing. Amaze us with your creativity !11@tool12def phrase_of_the_day_tool(category:str, number:int)-> str: #it's import to specify the return type13 #Keep this format for the description / args / args description but feel free to modify the tool14 """A tool that returns a phrase/motto of the day based on a chosen category and index. 15 Args:16 category: The category of phrases to choose from (e.g., 'motivation', 'support', 'cheer').17 number: The index of the phrase in that category.18 """19 phrases = {20 "motivation": [21 "Push yourself, because no one else is going to do it for you.",22 "Keep going. You didn’t come this far just to come this far.",23 "Every day is a second chance for success."24 ],25 "support": [26 "I’m here for you. Lean on me whenever you need.",27 "You’re more capable than you think!",28 "It’s okay to not be okay sometimes."29 ],30 "cheer": [31 "Hooray, it’s a new day to conquer!",32 "You’ve got this—keep it up!",33 "Let’s go! The world is yours to explore."34 ]35 }36 37 # Validate the category38 if category not in phrases:39 return "Unknown category. Please choose from 'motivation', 'support', or 'cheer'."40 41 # Validate the index42 chosen_category = phrases[category]43 if number < 0 or number >= len(chosen_category):44 return f"Invalid phrase number. Choose an index between 0 and {len(chosen_category)-1}."45 46 return chosen_category[number]47 48@tool49def get_current_time_in_timezone(timezone: str) -> str:50 """A tool that fetches the current local time in a specified timezone.51 Args:52 timezone: A string representing a valid timezone (e.g., 'America/New_York').53 """54 try:55 # Create timezone object56 tz = pytz.timezone(timezone)57 # Get current time in that timezone58 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")59 return f"The current local time in {timezone} is: {local_time}"60 except Exception as e:61 return f"Error fetching time for timezone '{timezone}': {str(e)}"62 63 64final_answer = FinalAnswerTool()65 66# 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:67# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' or (try onemore time model_id='Qwen/Qwen2.5-Coder-32B-Instruct',)68 69model = HfApiModel(70max_tokens=2096,71temperature=0.5,72model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded73custom_role_conversions=None,74)75 76 77# Import tool from Hub78image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)79 80with open("prompts.yaml", 'r') as stream:81 prompt_templates = yaml.safe_load(stream)82 83 84agent = CodeAgent(85 model=model,86 tools=[final_answer, phrase_of_the_day_tool], ## add your tools here (don't remove final answer)87 max_steps=6,88 verbosity_level=1,89 grammar=None,90 planning_interval=None,91 name=None,92 description=None,93 prompt_templates=prompt_templates94)95 96 97GradioUI(agent).launch()