shankarkool92/codeagent
0
1from smolagents import CodeAgent, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7from tools.web_search import DuckDuckGoSearchTool8from tools.visit_webpage import VisitWebpageTool9from Gradio_UI import GradioUI10 11# Below is an example of a tool that does nothing. Amaze us with your creativity !12 13@tool14def get_current_time_in_timezone(timezone: str) -> str:15 """A tool that fetches the current local time in a specified timezone.16 Args:17 timezone: A string representing a valid timezone (e.g., 'America/New_York').18 """19 try:20 # Create timezone object21 tz = pytz.timezone(timezone)22 # Get current time in that timezone23 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")24 return f"The current local time in {timezone} is: {local_time}"25 except Exception as e:26 return f"Error fetching time for timezone '{timezone}': {str(e)}"27 28 29final_answer = FinalAnswerTool()30search = DuckDuckGoSearchTool()31web = VisitWebpageTool()32# 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:33# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 34 35model = HfApiModel(36# max_tokens=2096,37temperature=0.5,38model_id='models/Qwen/Qwen2.5-Coder-32B-Instruct',# 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, search, web], ## 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()