Spaces:
Runtime error
Runtime error
| from smolagents import CodeAgent, LiteLLMModel , DuckDuckGoSearchTool, load_tool, tool | |
| import datetime | |
| import requests | |
| import pytz | |
| import yaml | |
| from tools.final_answer import FinalAnswerTool | |
| from Gradio_UI import GradioUI | |
| #A tool that does nothing | |
| def tool_does_nothing(a: str)-> str: | |
| """A tool that does nothing | |
| Args: | |
| a: A string input | |
| """ | |
| return "What does this tool do?" | |
| #A functioning second tool | |
| def get_current_time(arg1: str)->str: | |
| """A tool to get the current time | |
| Args: | |
| arg1: A string letting us know which timezone it is | |
| """ | |
| try: | |
| #Create timezone object | |
| timezone=pytz.timezone(arg1) | |
| current_time=datetime.datetime.now(timezone).strftime("%Y-%m-%d %H:%M:%S") | |
| return f"The current time in {arg1} is: {current_time}" | |
| except: | |
| return f"Time could not be calculated in timezone: '{arg1}' due to error {str(e)}" | |
| #Creating model instance with all parameters | |
| final_answer_tool=FinalAnswerTool() | |
| model=LiteLLMModel( | |
| model_id='Qwen/Qwen2.5-Coder-32B-Instruct', | |
| max_tokens=2096, | |
| temperature=0.4, | |
| custom_role_conversions=None | |
| ) | |
| #import image generation tool from hub | |
| image_generation=load_tool("agents-course/text-to-image",trust_remote_code=True) | |
| #import sysytem prompt from yaml file | |
| with open("prompts.yaml",'r') as stream: | |
| prompt_text=yaml.safe_load(stream) | |
| #Creating the agent | |
| agent=CodeAgent( | |
| model=model, | |
| tools=[tool_does_nothing,get_current_time,final_answer_tool], | |
| max_steps=6, | |
| grammar=None, | |
| verbosity_level=1, | |
| planning_interval=None, | |
| name=None, | |
| description=None, | |
| prompt_templates=prompt_text | |
| ) | |
| GradioUI(agent).launch |