Spaces:
Runtime error
Runtime error
File size: 1,831 Bytes
80bcb56 5401172 9b5b26a c19d193 6aae614 cce7bec 9b5b26a 4e051ec 2ad9e60 5401172 51d2b7d 5401172 51d2b7d 5401172 51d2b7d 5401172 9b99c63 5401172 9b5b26a 5401172 9b5b26a 5401172 9b5b26a 5401172 8c01ffb 5401172 8c01ffb ae7a494 80bcb56 8c01ffb 95f56e7 9848f16 fc4fa81 9848f16 98d293e 8c01ffb 70e2343 f97ce1b 70e2343 8fe992b d829467 b952afe 80bcb56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
from smolagents import CodeAgent,HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
@tool
def add_numbers(a: int, b: int) -> int:
"""
Add two numbers together.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The sum of the two numbers.
"""
return a + b
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""
Get the current time in a given timezone.
Args:
timezone (str): A valid timezone string (e.g., 'America/New_York').
Returns:
str: The current time in that timezone, formatted as a string.
"""
from datetime import datetime
import pytz
tz = pytz.timezone(timezone)
now = datetime.now(tz)
return now.strftime("%Y-%m-%d %H:%M:%S %Z")
# 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:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
max_tokens=1024,
temperature=0.5
)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
tool=[
"add_numbers",
"get_current_time_in_timezone", "FinalAnswerTool"
]
agent = CodeAgent(
model=model,
tools=[add_numbers, get_current_time_in_timezone],
max_steps=6,
verbosity_level=1,
name="PracticeAgent",
description="Agent with simple math and time tools",
prompt_templates=prompt_templates
)
# Entry Point
if __name__ == "__main__":
print(agent.run("What is 6 + 99, and also tell me the current time in US/Pacific")) |