Team Ai
Apppublic

Cooing-code/First_agent_template

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
app.py51 linesDownload Raw Back to root
1import os2import datetime3import pytz4 5from smolagents import CodeAgent, InferenceClientModel, tool6from tools.final_answer import FinalAnswerTool7from Gradio_UI import GradioUI8 9 10@tool11def reverse_text(text: str) -> str:12    """Reverse the input text.13    Args:14        text: The text to reverse.15    """16    return text[::-1]17 18 19@tool20def get_current_time_in_timezone(timezone: str) -> str:21    """Fetch the current local time in a specified timezone.22    Args:23        timezone: A valid timezone string, for example 'Asia/Shanghai'.24    """25    try:26        tz = pytz.timezone(timezone)27        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")28        return f"The current local time in {timezone} is: {local_time}"29    except Exception as e:30        return f"Error fetching time for timezone '{timezone}': {str(e)}"31 32 33final_answer = FinalAnswerTool()34 35model = InferenceClientModel(36    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",37    token=os.environ.get("HF_TOKEN"),38    max_tokens=2048,39)40 41agent = CodeAgent(42    model=model,43    tools=[final_answer, reverse_text, get_current_time_in_timezone],44    max_steps=6,45    verbosity_level=1,46    planning_interval=None,47    name="MyFirstAgent",48    description="An agent that can reverse text and check timezones.",49)50 51GradioUI(agent).launch()