Erik/First_agent_template
0
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7from dotenv import load_dotenv8from Gradio_UI import GradioUI9import os10 11load_dotenv()12 13HF_TOKEN = os.getenv("HF_TOKEN")14 15 16# Below is an example of a tool that does nothing. Amaze us with your creativity !17@tool18def alarm_comparator_degrees(weather_average_degrees:float, optimal_fermentation_degrees:float)-> str: #it's import to specify the return type19 #Keep this format for the description / args / args description but feel free to modify the tool20 """A tool that compares the actual weathers degrees and the optimal fermentation degrees of a product in order to flag with an alert!!21 22 Args:23 weather_average_degrees: A float representing the avarage degrees of current weather.24 optimal_fermentation_degrees: A float representing the degrees that should be the fermentation process.25 """26 try:27 dif_degrees = weather_average_degrees - optimal_fermentation_degrees28 if abs(dif_degrees) >= 1.5:29 if dif_degrees < 0:30 return f"RED LIGHT - the difference degrees between optimal and current weather are {str(dif_degrees)}ºC - YOU SHOULD INCREASE THE HEATER BY {str(dif_degrees)}ºC!" 31 else:32 return f"RED LIGHT - the difference degrees between optimal and current weather are {str(dif_degrees)}ºC - YOU SHOULD DECREASE THE HEATER BY {str(dif_degrees)}ºC!" 33 else:34 return f"GREEN LIGHT - the difference degrees between optimal and current weather are {str(dif_degrees)} - DEGREES FOR FERMENTATION IN RANGE!"35 except Exception as e:36 return f"Error fetching {str(weather_average_degrees)} and {str(optimal_fermentation_degrees)}."37 38 39@tool40def get_current_time_in_timezone(timezone: str) -> str:41 """A tool that fetches the current local time in a specified timezone.42 Args:43 timezone: A string representing a valid timezone (e.g., 'America/New_York').44 """45 try:46 # Create timezone object47 tz = pytz.timezone(timezone)48 # Get current time in that timezone49 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")50 return f"The current local time in {timezone} is: {local_time}"51 except Exception as e:52 return f"Error fetching time for timezone '{timezone}': {str(e)}"53 54 55search_info_tool = DuckDuckGoSearchTool()56 57final_answer = FinalAnswerTool()58 59model = HfApiModel(60 max_tokens=2096,61 temperature=0.5,62 model_id="Qwen/Qwen2.5-Coder-32B-Instruct",63 #model_id='mistralai/Mistral-Small-24B-Instruct-2501',64 #model_id="deepseek-ai/DeepSeek-V3",65 custom_role_conversions=None,66 token=HF_TOKEN,67)68 69# Import tool from Hub70image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)71 72with open("prompts.yaml", 'r') as stream:73 prompt_templates = yaml.safe_load(stream)74 75agent = CodeAgent(76 model=model,77 tools=[get_current_time_in_timezone, search_info_tool, alarm_comparator_degrees, image_generation_tool, final_answer], ## add your tools here (don't remove final answer)78 max_steps=6,79 verbosity_level=1,80 grammar=None,81 planning_interval=None,82 name=None,83 description=None,84 prompt_templates=prompt_templates85)86 87 88GradioUI(agent).launch()