Team Ai
Apppublic

marques-gui/First_agent_template

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py63 linesDownload Raw Back to root
1from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, load_tool, tool2import datetime3import requests4import pytz5import yaml6 7from Gradio_UI import GradioUI8 9@tool10def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type11    # Keep this format for the tool description / args description but feel free to modify the tool12    """A tool that does nothing yet 13    Args:14        arg1: the first argument15        arg2: the second argument16    """17    return "What magic will you build ?"18 19@tool20def get_current_time_in_timezone(timezone: str) -> str:21    """A tool that fetches the current local time in a specified timezone.22    Args:23        timezone: A string representing a valid timezone (e.g., 'America/New_York').24    """25    try:26        # Create timezone object27        tz = pytz.timezone(timezone)28        # Get current time in that timezone29        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")30        return f"The current local time in {timezone} is: {local_time}"31    except Exception as e:32        return f"Error fetching time for timezone '{timezone}': {str(e)}"33 34final_answer = FinalAnswerTool()35 36# 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:37# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 38 39final_answer = FinalAnswerTool()40model = HfApiModel(41    max_tokens=2096,42    temperature=0.5,43    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',44    custom_role_conversions=None,45)46 47with open("prompts.yaml", 'r') as stream:48    prompt_templates = yaml.safe_load(stream)49    50# We're creating our CodeAgent51agent = CodeAgent(52    model=model,53    tools=[get_current_time_in_timezone, final_answer], # add your tools here (don't remove final_answer)54    max_steps=6,55    verbosity_level=1,56    grammar=None,57    planning_interval=None,58    name=None,59    description=None,60    prompt_templates=prompt_templates61)62 63GradioUI(agent).launch()