Download agent.py from VinceAjello/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/VinceAjello/Final_Assignment_Template/resolve/main/agent.py
- Command line
-
hf download hf://spaces/VinceAjello/Final_Assignment_Template/agent.py
-
curl -L -o agent.py https://huggingface.co/spaces/VinceAjello/Final_Assignment_Template/resolve/main/agent.py
2.68 kB
| # | |
| # GAIA's team suggested system prompt: | |
| # You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. | |
| # | |
| import sys | |
| import time | |
| # https://github.com/huggingface/smolagents/issues/1134 | |
| def delay_execution(pagent, **kwargs) -> bool: | |
| """ | |
| Delays the execution for 10 seconds. | |
| """ | |
| time.sleep(10) | |
| return True | |
| STEP_CALLBACKS = [delay_execution] | |
| from smolagents import OpenAIServerModel | |
| from smolagents.agents import ToolCallingAgent | |
| from src.toolkit import Toolkit | |
| class MyAgent: | |
| def __init__(self, api_key): | |
| tk = Toolkit() | |
| toolkit = tk.get() | |
| # model = OpenAIServerModel( model_id="gemma-3-12b-it", api_base="http://127.0.0.1:1234/v1/", api_key="nono") | |
| model = OpenAIServerModel( model_id="gpt-4.1-mini", api_key=api_key) | |
| self.agent = ToolCallingAgent( tools=toolkit, model=model, planning_interval=3, step_callbacks=STEP_CALLBACKS) | |
| def answer(self, question, file=None): | |
| prompt = f"""You are a general AI assistant. | |
| I will ask you a question. Report your thoughts, | |
| and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. | |
| YOUR FINAL ANSWER should be a number in numeric form OR as few words as possible OR a comma separated list of numbers and/or strings. | |
| If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. | |
| If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. | |
| If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. | |
| Question: {question}""" | |
| return self.agent.run(prompt) | |
| if __name__ == "__main__": | |
| argv = sys.argv | |
| if len(argv) < 2: | |
| print("Ask me something :)") | |
| exit(0) | |
| a = MyAgent().answer(argv[1]) | |
| print(a) |