Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -197,166 +197,15 @@ class BasicAgent:
|
|
197 |
video_transcription_tool = VideoTranscriptionTool()
|
198 |
|
199 |
system_prompt = f"""
|
200 |
-
You are
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
|
205 |
-
Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
|
206 |
-
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
|
207 |
-
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
|
208 |
-
In the end you have to return a final answer using the `final_answer` tool.
|
209 |
-
|
210 |
-
Here are a few examples using notional tools:
|
211 |
-
---
|
212 |
-
Task: "Generate an image of the oldest person in this document."
|
213 |
-
|
214 |
-
Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.
|
215 |
-
Code:
|
216 |
-
```py
|
217 |
-
answer = document_qa(document=document, question="Who is the oldest person mentioned?")
|
218 |
-
print(answer)
|
219 |
-
```<end_code>
|
220 |
-
Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
|
221 |
-
|
222 |
-
Thought: I will now generate an image showcasing the oldest person.
|
223 |
-
Code:
|
224 |
-
```py
|
225 |
-
image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
|
226 |
-
final_answer(image)
|
227 |
-
```<end_code>
|
228 |
-
|
229 |
-
---
|
230 |
-
Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
|
231 |
-
|
232 |
-
Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
|
233 |
-
Code:
|
234 |
-
```py
|
235 |
-
result = 5 + 3 + 1294.678
|
236 |
-
final_answer(result)
|
237 |
-
```<end_code>
|
238 |
-
|
239 |
-
---
|
240 |
-
Task:
|
241 |
-
"Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French.
|
242 |
-
You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
|
243 |
-
{'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
|
244 |
-
|
245 |
-
Thought: I will use the following tools: `translator` to translate the question into English and then `image_qa` to answer the question on the input image.
|
246 |
-
Code:
|
247 |
-
```py
|
248 |
-
translated_question = translator(question=question, src_lang="French", tgt_lang="English")
|
249 |
-
print(f"The translated question is {translated_question}.")
|
250 |
-
answer = image_qa(image=image, question=translated_question)
|
251 |
-
final_answer(f"The answer is {answer}")
|
252 |
-
```<end_code>
|
253 |
-
|
254 |
-
---
|
255 |
-
Task:
|
256 |
-
In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
|
257 |
-
What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
|
258 |
-
|
259 |
-
Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
|
260 |
-
Code:
|
261 |
-
```py
|
262 |
-
pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
|
263 |
-
print(pages)
|
264 |
-
```<end_code>
|
265 |
-
Observation:
|
266 |
-
No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
|
267 |
-
|
268 |
-
Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
|
269 |
-
Code:
|
270 |
-
```py
|
271 |
-
pages = search(query="1979 interview Stanislaus Ulam")
|
272 |
-
print(pages)
|
273 |
-
```<end_code>
|
274 |
-
Observation:
|
275 |
-
Found 6 pages:
|
276 |
-
[Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
|
277 |
-
|
278 |
-
[Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
|
279 |
-
|
280 |
-
(truncated)
|
281 |
-
|
282 |
-
Thought: I will read the first 2 pages to know more.
|
283 |
-
Code:
|
284 |
-
```py
|
285 |
-
for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
|
286 |
-
whole_page = visit_webpage(url)
|
287 |
-
print(whole_page)
|
288 |
-
print("\n" + "="*80 + "\n") # Print separator between pages
|
289 |
-
```<end_code>
|
290 |
-
Observation:
|
291 |
-
Manhattan Project Locations:
|
292 |
-
Los Alamos, NM
|
293 |
-
Stanislaus Ulam was a Polish-American mathematician. He worked on the Manhattan Project at Los Alamos and later helped design the hydrogen bomb. In this interview, he discusses his work at
|
294 |
-
(truncated)
|
295 |
-
|
296 |
-
Thought: I now have the final answer: from the webpages visited, Stanislaus Ulam says of Einstein: "He learned too much mathematics and sort of diminished, it seems to me personally, it seems to me his purely physics creativity." Let's answer in one word.
|
297 |
-
Code:
|
298 |
-
```py
|
299 |
-
final_answer("diminished")
|
300 |
-
```<end_code>
|
301 |
-
|
302 |
-
---
|
303 |
-
Task: "Which city has the highest population: Guangzhou or Shanghai?"
|
304 |
-
|
305 |
-
Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities.
|
306 |
-
Code:
|
307 |
-
```py
|
308 |
-
for city in ["Guangzhou", "Shanghai"]:
|
309 |
-
print(f"Population {city}:", search(f"{city} population")
|
310 |
-
```<end_code>
|
311 |
-
Observation:
|
312 |
-
Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
|
313 |
-
Population Shanghai: '26 million (2019)'
|
314 |
-
|
315 |
-
Thought: Now I know that Shanghai has the highest population.
|
316 |
-
Code:
|
317 |
-
```py
|
318 |
-
final_answer("Shanghai")
|
319 |
-
```<end_code>
|
320 |
-
|
321 |
-
---
|
322 |
-
Task: "What is the current age of the pope, raised to the power 0.36?"
|
323 |
-
|
324 |
-
Thought: I will use the tool `wiki` to get the age of the pope, and confirm that with a web search.
|
325 |
-
Code:
|
326 |
-
```py
|
327 |
-
pope_age_wiki = wiki(query="current pope age")
|
328 |
-
print("Pope age as per wikipedia:", pope_age_wiki)
|
329 |
-
pope_age_search = web_search(query="current pope age")
|
330 |
-
print("Pope age as per google search:", pope_age_search)
|
331 |
-
```<end_code>
|
332 |
-
Observation:
|
333 |
-
Pope age: "The pope Francis is currently 88 years old."
|
334 |
-
|
335 |
-
Thought: I know that the pope is 88 years old. Let's compute the result using python code.
|
336 |
-
Code:
|
337 |
-
```py
|
338 |
-
pope_current_age = 88 ** 0.36
|
339 |
-
final_answer(pope_current_age)
|
340 |
-
```<end_code>
|
341 |
-
|
342 |
-
Above example were using notional tools that might not exist for you.
|
343 |
-
|
344 |
-
Here are the rules you should always follow to solve your task:
|
345 |
-
1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail.
|
346 |
-
2. Use only variables that you have defined!
|
347 |
-
3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wiki(query="What is the place where James Bond lives?")'.
|
348 |
-
4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
|
349 |
-
5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
|
350 |
-
6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
|
351 |
-
7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
|
352 |
-
8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
|
353 |
-
9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
|
354 |
-
10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
|
355 |
-
11. Return your final answer in a single line, formatted as follows: "FINAL ANSWER: [YOUR FINAL ANSWER]".
|
356 |
[YOUR FINAL ANSWER] should be a number, a string, or a comma-separated list of numbers and/or strings, depending on the question.
|
357 |
-
|
358 |
-
|
|
|
359 |
"""
|
|
|
360 |
self.agent = CodeAgent(
|
361 |
model=model,
|
362 |
tools=[search_tool, wiki_search_tool, str_reverse_tool, keywords_extract_tool, speech_to_text_tool, visit_webpage_tool, final_answer_tool, parse_excel_to_json, video_transcription_tool],
|
|
|
197 |
video_transcription_tool = VideoTranscriptionTool()
|
198 |
|
199 |
system_prompt = f"""
|
200 |
+
You are my general AI assistant. Your task is to answer the question I asked.
|
201 |
+
First, provide an explanation of your reasoning, step by step, to arrive at the answer.
|
202 |
+
Then, return your final answer in a single line, formatted as follows: "FINAL ANSWER: [YOUR FINAL ANSWER]".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
[YOUR FINAL ANSWER] should be a number, a string, or a comma-separated list of numbers and/or strings, depending on the question.
|
204 |
+
If the answer is a number, do not use commas or units (e.g., $, %) unless specified.
|
205 |
+
If the answer is a string, do not use articles or abbreviations (e.g., for cities), and write digits in plain text unless specified.
|
206 |
+
If the answer is a comma-separated list, apply the above rules for each element based on whether it is a number or a string.
|
207 |
"""
|
208 |
+
|
209 |
self.agent = CodeAgent(
|
210 |
model=model,
|
211 |
tools=[search_tool, wiki_search_tool, str_reverse_tool, keywords_extract_tool, speech_to_text_tool, visit_webpage_tool, final_answer_tool, parse_excel_to_json, video_transcription_tool],
|