File size: 6,574 Bytes
9b5b26a c19d193 6aae614 8fe992b 9b5b26a 5df72d6 6441338 9b5b26a 6441338 1ea669c 6441338 1ea669c 6441338 1ea669c 6441338 1ea669c 6441338 1ea669c 6441338 1ea669c 6441338 9b5b26a 6441338 9b5b26a 6441338 9b5b26a 8c01ffb 6aae614 ae7a494 e121372 bf6d34c 29ec968 fe328e0 13d500a 8c01ffb 9b5b26a 6441338 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b 6441338 8c01ffb f2c836a 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb |
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def calculator(number1: float, number2: float, operation: str)-> float:
"""A tool that does three kinds of maths operations: sum, subtract, divide, or multiply.
Args:
number1: The first float number, it can be int
number2: the second float number, it can be int
operation: the type of math operation to carry out, it can be sum, subtraction (subtract), division(divide), or multiplication (multiply).
"""
try:
if type(number1)== int:
number1= float(number1)
if type(number2)== int:
number2= float(number2)
if operation == "sum":
result= number1 + number2
elif operation == "subtract":
result= number1 - number2
elif operation == "divide":
result= number1 /number2
elif operation == "multiply":
result= number1 * number2
return result
except Exception as e:
return f"Error: {e}. Operation not surpported or missing arguments."
@tool
def sing_defying_gravity()-> str: #it's import to specify the return type
"""A tool that returns the lyrics for Defying Gravity
Args:
no arguments
"""
lyrics= """
[Glinda]
Elphaba
Why couldn't you have stayed calm for once
Instead of flying off the handle?
I hope you're happy
I hope you're happy now
I hope you're happy how you've hurt your cause forever
I hope you think you're clever
[Elphaba]
I hope you're happy
I hope you're happy too
I hope you're proud how you would grovel in submission
To feed your own ambition
[Galinda and Elphaba]
So though I can't imagine how
I hope you're happy right now
[Glinda]
Elphie, listen to me
Just say you're sorry
You can still be with the wizard
What you've worked and waited for
You can have all you ever wanted
[Elphaba]
I know
But I don't want it
No
I can't want it anymore
Something has changed within me
Something is not the same
I'm through with playing by the rules of someone else's game
Too late for second-guessing
Too late to go back to sleep
It's time to trust my instincts
Close my eyes and leap
It's time to try defying gravity
I think I'll try defying gravity
And you can't pull me down
[Glinda]
Can't I make you understand
You're having delusions of grandeur?
[Elphaba]
I'm through accepting limits
'Cause someone says they're so
Some things I cannot change
But till I try, I'll never know
Too long I've been afraid of
Losing love, I guess I've lost
Well, if that's love
It comes at much too high a cost
I'd sooner buy defying gravity
Kiss me goodbye, I'm defying gravity
And you can't pull me down
Glinda
Come with me
Think of what we could do
Together
Unlimited
Together we're unlimited
Together we'll be the greatest team there's ever been, Glinda
Dreams the way we planned 'em
[Glinda]
If we work in tandem
[Glinda and Elphaba]
There's no fight we cannot win
Just you and I defying gravity
With you and I defying gravity
[Elphaba]
They'll never bring us down
Well, are you coming?
[Glinda]
I hope you're happy
Now that you're choosing this
[Elphaba]
You too
I hope it brings you bliss
[Glinda and Elphaba]
I really hope you get it
And you don't live to regret it
I hope you're happy in the end
I hope you're happy, my friend
[Elphaba]
No, leave her alone
She hasn't done anything wrong
I'm the one you want
I'm the one you want
It's me
It's me
So if you care to find me, look to the western sky
As someone told me lately
Everyone deserves the chance to fly
And if I'm flying solo
At least I'm flying free
To those who'd ground me
Take a message back from me
Tell them how I am defying gravity
I'm flying high, defying gravity
And soon I'll match them in renown
Unlimited
Unlimited
Unlimited, oh
And nobody in all of Oz
No wizard that there is or was
Is ever gonna bring me down
[Glinda]
I hope you're happy
[Citizens of Oz and Elphaba]
Look at her, she's wicked, kill her!
(Bring me down) no one mourns the wicked
So we've got to bring her
(Oh) down
Down, woah
"""
return lyrics
@tool
def get_current_time_in_timezone(timezone: str) -> str:
"""A tool that fetches the current local time in a specified timezone.
Args:
timezone: A string representing a valid timezone (e.g., 'America/New_York').
"""
try:
# Create timezone object
tz = pytz.timezone(timezone)
# Get current time in that timezone
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
return f"The current local time in {timezone} is: {local_time}"
except Exception as e:
return f"Error fetching time for timezone '{timezone}': {str(e)}"
final_answer = FinalAnswerTool()
# 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(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
custom_role_conversions=None,
)
# Import tool from Hub
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
search_tool = DuckDuckGoSearchTool()
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer, image_generation_tool, search_tool, calculator,sing_defying_gravity], ## add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name="Dumbo",
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |