Team Ai
Apppublic

CoderBurntt/First_agent_template

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py64 linesDownload Raw Back to root
1from smolagents import CodeAgent, HfApiModel, load_tool2import yaml3from tools.final_answer import FinalAnswerTool4from Gradio_UI import GradioUI5from tools.visit_webpage import VisitWebpageTool6from tools.web_search import DuckDuckGoSearchTool7 8# Define custom tools9def my_custom_tool(arg1: str, arg2: int) -> str:10    """A tool that does nothing yet 11    Args:12        arg1: the first argument13        arg2: the second argument14    """15    return "What magic will you build ?"16 17def get_current_time_in_timezone(timezone: str) -> str:18    """A tool that fetches the current local time in a specified timezone.19    Args:20        timezone: A string representing a valid timezone (e.g., 'America/New_York').21    """22    try:23        tz = pytz.timezone(timezone)24        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")25        return f"The current local time in {timezone} is: {local_time}"26    except Exception as e:27        return f"Error fetching time for timezone '{timezone}': {str(e)}"28 29# Configure the model30final_answer = FinalAnswerTool()31model = HfApiModel(32    max_tokens=2096,33    temperature=0.5,34    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',35    custom_role_conversions=None,36)37 38# Load additional tools39image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)40 41# Load system prompt42with open("prompts.yaml", 'r') as stream:43    prompt_templates = yaml.safe_load(stream)44 45# Create the agent46agent = CodeAgent(47    model=model,48    tools=[49        final_answer,50        image_generation_tool,51        VisitWebpageTool(),52        DuckDuckGoSearchTool()53    ],  # Add your tools here54    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 63# Launch the agent64GradioUI(agent).launch()