virtive2003/BasicAg
0
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool2import datetime3import requests4import pytz5import yaml6from tools.final_answer import FinalAnswerTool7 8from Gradio_UI import GradioUI9 10# Below is an example of a tool that does nothing. Amaze us with your creativity !11@tool12def simple_card_gam(username:str)-> str: #it's import to specify the return type13 #Keep this format for the description / args / args description but feel free to modify the tool14 """Plays a one-card game between the user and the agent.15 Each player is randomly dealt one card.16 The higher card wins based on predefined card and suit rankings.17 18 Args:19 username: the name of the player20 """21 card_values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]22 suites = {"Clubs": 1, "Diamonds": 2, "Hearts": 3, "Spades": 4}23 import random24 while True:25 user_card = random.choice(card_values)26 user_suite = random.choice(list(suites.keys()))27 agent_card = random.choice(card_values)28 agent_suite = random.choice(list(suites.keys()))29 if user_card != agent_card or user_suite != agent_suite:30 break31 if card_values.index(user_card) > card_values.index(agent_card):32 result = f"{username} wins with {user_card} of {user_suite} against agent's {agent_card} of {agent_suite}."33 elif card_values.index(user_card) < card_values.index(agent_card):34 result = f"Agent wins with {agent_card} of {agent_suite} against {username}'s {user_card} of {user_suite}."35 else:36 if suites[user_suite] > suites[agent_suite]:37 result = f"{username} wins with {user_card} of {user_suite} against agent's {agent_card} of {agent_suite}."38 elif suites[user_suite] < suites[agent_suite]:39 result = f"Agent wins with {agent_card} of {agent_suite} against {username}'s {user_card} of {user_suite}."40 return result41 42@tool43def get_current_time_in_timezone(timezone: str) -> str:44 """A tool that fetches the current local time in a specified timezone.45 Args:46 timezone: A string representing a valid timezone (e.g., 'America/New_York').47 """48 try:49 # Create timezone object50 tz = pytz.timezone(timezone)51 # Get current time in that timezone52 local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")53 return f"The current local time in {timezone} is: {local_time}"54 except Exception as e:55 return f"Error fetching time for timezone '{timezone}': {str(e)}"56 57 58final_answer = FinalAnswerTool()59 60# 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:61# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' 62 63model = HfApiModel(64max_tokens=2096,65temperature=0.5,66model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded67custom_role_conversions=None,68)69 70 71# Import tool from Hub72image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)73 74with open("prompts.yaml", 'r') as stream:75 prompt_templates = yaml.safe_load(stream)76 77agent = CodeAgent(78 model=model,79 tools=[final_answer], ## add your tools here (don't remove final answer)80 max_steps=6,81 verbosity_level=1,82 grammar=None,83 planning_interval=None,84 name=None,85 description=None,86 prompt_templates=prompt_templates87)88 89 90GradioUI(agent).launch()