CoolFace
Apppublic

EbbFlow/First_agent_template

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py75 linesDownload Raw Back to root
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7import random8 9from Gradio_UI import GradioUI10 11# Below is an example of a tool that does nothing. Amaze us with your creativity !12@tool13def random_inspirational_quote()-> str: #it's import to specify the return type14    """A tool that returns a random inspirational quote.15    16    Returns:17        A random inspirational quote as a string.18    """19    quotes = [20        "Believe you can and you're halfway there.",21        "Your limitation—it's only your imagination.",22        "Push yourself, because no one else is going to do it for you.",23        "Sometimes later becomes never. Do it now.",24        "Great things never come from comfort zones.",25        "Dream big and dare to fail.",26        "Keep your eyes on the stars, and your feet on the ground.",27        "The only way to do great work is to love what you do."28    ]29    return random.choice(quotes)30 31@tool32def get_current_time_in_timezone(timezone: str) -> str:33    """A tool that fetches the current local time in a specified timezone.34    Args:35        timezone: A string representing a valid timezone (e.g., 'America/New_York').36    """37    try:38        # Create timezone object39        tz = pytz.timezone(timezone)40        # Get current time in that timezone41        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")42        return f"The current local time in {timezone} is: {local_time}"43    except Exception as e:44        return f"Error fetching time for timezone '{timezone}': {str(e)}"45 46 47final_answer = FinalAnswerTool()48model = HfApiModel(49max_tokens=2096,50temperature=0.5,51model_id='Qwen/Qwen2.5-Coder-32B-Instruct',52custom_role_conversions=None,53)54 55 56# Import tool from Hub57image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)58 59with open("prompts.yaml", 'r') as stream:60    prompt_templates = yaml.safe_load(stream)61    62agent = CodeAgent(63    model=model,64    tools=[final_answer,  random_inspirational_quote], ## add your tools here (don't remove final answer)65    max_steps=6,66    verbosity_level=1,67    grammar=None,68    planning_interval=None,69    name=None,70    description=None,71    prompt_templates=prompt_templates72)73 74 75GradioUI(agent).launch()