CoolFace
Apppublic

clickstuff/First_agent_template

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py83 linesDownload Raw Back to root
1import os2from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel3 4hf_token = os.getenv("HF_TOKEN")5 6# Debugging: Check if the token is loaded7if hf_token is None:8    raise ValueError("HF_TOKEN environment variable is not set. Make sure it's added in the Space secrets.")9else:10    print(f"HF_TOKEN detected with length {len(hf_token)} characters.") 11 12agent = CodeAgent(13    tools=[DuckDuckGoSearchTool()],14    model=HfApiModel(token=hf_token)15)16 17agent.run("How many days would it take to drive through each state in America?")18 19 20'''import datetime21import requests22import pytz23import yaml24from tools.final_answer import FinalAnswerTool25 26from Gradio_UI import GradioUI27 28# Below is an example of a tool that does nothing. Amaze us with your creativity !29@tool30def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type31    #Keep this format for the description / args / args description but feel free to modify the tool32    """A tool that does nothing yet 33    Args:34        arg1: the first argument35        arg2: the second argument36    """37    return "What magic will you build ?"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 55final_answer = FinalAnswerTool()56model = HfApiModel(57max_tokens=2096,58temperature=0.5,59model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded60custom_role_conversions=None,61)62 63 64# Import tool from Hub65image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)66 67with open("prompts.yaml", 'r') as stream:68    prompt_templates = yaml.safe_load(stream)69    70agent = CodeAgent(71    model=model,72    tools=[final_answer], ## add your tools here (don't remove final answer)73    max_steps=6,74    verbosity_level=1,75    grammar=None,76    planning_interval=None,77    name=None,78    description=None,79    prompt_templates=prompt_templates80)81 82 83GradioUI(agent).launch()'''