StivenLancheros commited on
Commit
6441338
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

Adding new tools

Files changed (1) hide show
  1. app.py +171 -7
app.py CHANGED
@@ -8,15 +8,178 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  """
19
- return "What magic will you build ?"
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -49,13 +212,14 @@ custom_role_conversions=None,
49
 
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+
12
  @tool
13
+ def calculator(number1: float, number2: float, operation: str)-> float:
14
+ """A tool that does three kinds of maths operations
15
+ Args:
16
+ number1: The first float number, it can be int
17
+ number2: the second float number, it can be int
18
+ operation: the type of math operation to carry out.
19
+ """
20
+ try:
21
+ if type(number1)== int:
22
+ number1= float(number1)
23
+ if type(number2)== int:
24
+ number2= float(number2)
25
+ if operation == "sum":
26
+ result= number1 + number2
27
+ elif operation == "subtraction":
28
+ result= number1 - number2
29
+ elif operation == "division":
30
+ result= number1 /number2
31
+ elif operation == "multiplication":
32
+ result= number1 * number2
33
+
34
+ return result
35
+ except Exception as e:
36
+ return f"Error: {e}. Operation not surpported or missing arguments."
37
+
38
+ @tool
39
+ def sing_defying_gravity()-> str: #it's import to specify the return type
40
+
41
+ """A tool that returns the lyrics for Defying Gravity
42
  Args:
43
+ no arguments
44
+ """
45
+ lyrics= """
46
+ [Glinda]
47
+ Elphaba
48
+ Why couldn't you have stayed calm for once
49
+ Instead of flying off the handle?
50
+ I hope you're happy
51
+ I hope you're happy now
52
+ I hope you're happy how you've hurt your cause forever
53
+ I hope you think you're clever
54
+
55
+ [Elphaba]
56
+ I hope you're happy
57
+ I hope you're happy too
58
+ I hope you're proud how you would grovel in submission
59
+ To feed your own ambition
60
+
61
+ [Galinda and Elphaba]
62
+ So though I can't imagine how
63
+ I hope you're happy right now
64
+
65
+ [Glinda]
66
+ Elphie, listen to me
67
+ Just say you're sorry
68
+ You can still be with the wizard
69
+ What you've worked and waited for
70
+ You can have all you ever wanted
71
+
72
+ [Elphaba]
73
+ I know
74
+ But I don't want it
75
+ No
76
+ I can't want it anymore
77
+
78
+ Something has changed within me
79
+ Something is not the same
80
+ I'm through with playing by the rules of someone else's game
81
+ Too late for second-guessing
82
+ Too late to go back to sleep
83
+ It's time to trust my instincts
84
+ Close my eyes and leap
85
+
86
+ It's time to try defying gravity
87
+ I think I'll try defying gravity
88
+ And you can't pull me down
89
+
90
+ [Glinda]
91
+ Can't I make you understand
92
+ You're having delusions of grandeur?
93
+
94
+ [Elphaba]
95
+ I'm through accepting limits
96
+ 'Cause someone says they're so
97
+ Some things I cannot change
98
+ But till I try, I'll never know
99
+ Too long I've been afraid of
100
+ Losing love, I guess I've lost
101
+ Well, if that's love
102
+ It comes at much too high a cost
103
+
104
+ I'd sooner buy defying gravity
105
+ Kiss me goodbye, I'm defying gravity
106
+ And you can't pull me down
107
+
108
+ Glinda
109
+ Come with me
110
+ Think of what we could do
111
+ Together
112
+
113
+ Unlimited
114
+ Together we're unlimited
115
+ Together we'll be the greatest team there's ever been, Glinda
116
+ Dreams the way we planned 'em
117
+
118
+ [Glinda]
119
+ If we work in tandem
120
+
121
+ [Glinda and Elphaba]
122
+ There's no fight we cannot win
123
+ Just you and I defying gravity
124
+ With you and I defying gravity
125
+
126
+ [Elphaba]
127
+ They'll never bring us down
128
+ Well, are you coming?
129
+
130
+ [Glinda]
131
+ I hope you're happy
132
+ Now that you're choosing this
133
+
134
+ [Elphaba]
135
+ You too
136
+ I hope it brings you bliss
137
+
138
+ [Glinda and Elphaba]
139
+ I really hope you get it
140
+ And you don't live to regret it
141
+ I hope you're happy in the end
142
+ I hope you're happy, my friend
143
+
144
+ [Elphaba]
145
+ No, leave her alone
146
+ She hasn't done anything wrong
147
+ I'm the one you want
148
+ I'm the one you want
149
+ It's me
150
+ It's me
151
+
152
+ So if you care to find me, look to the western sky
153
+ As someone told me lately
154
+ Everyone deserves the chance to fly
155
+ And if I'm flying solo
156
+ At least I'm flying free
157
+ To those who'd ground me
158
+ Take a message back from me
159
+
160
+ Tell them how I am defying gravity
161
+ I'm flying high, defying gravity
162
+ And soon I'll match them in renown
163
+
164
+ Unlimited
165
+ Unlimited
166
+ Unlimited, oh
167
+
168
+ And nobody in all of Oz
169
+ No wizard that there is or was
170
+ Is ever gonna bring me down
171
+
172
+ [Glinda]
173
+ I hope you're happy
174
+
175
+ [Citizens of Oz and Elphaba]
176
+ Look at her, she's wicked, kill her!
177
+ (Bring me down) no one mourns the wicked
178
+ So we've got to bring her
179
+ (Oh) down
180
+ Down, woah
181
  """
182
+ return lyrics
183
 
184
  @tool
185
  def get_current_time_in_timezone(timezone: str) -> str:
 
212
 
213
  # Import tool from Hub
214
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
215
+ search_tool = DuckDuckGoSearchTool()
216
 
217
  with open("prompts.yaml", 'r') as stream:
218
  prompt_templates = yaml.safe_load(stream)
219
 
220
  agent = CodeAgent(
221
  model=model,
222
+ tools=[final_answer, image_generation_tool, search_tool, calculator,sing_defying_gravity], ## add your tools here (don't remove final answer)
223
  max_steps=6,
224
  verbosity_level=1,
225
  grammar=None,