navodit17/Final_Assignment_Template
0
1from dotenv import load_dotenv2from smolagents import CodeAgent3from smolagents import OpenAIServerModel4from tool import fetch_webpage, read_file_tool, get_youtube_transcript, transcribe_audio5 6from smolagents import VisitWebpageTool, WikipediaSearchTool, PythonInterpreterTool, DuckDuckGoSearchTool, WebSearchTool, SpeechToTextTool7 8from prompt import gaia_prompt9 10load_dotenv()11 12openai_nano_model = OpenAIServerModel(13 # model_id="gpt-4.1-nano-2025-04-14",14 model_id="gpt-4.1-mini-2025-04-14",15 # model_id="o3-mini-2025-01-31",16)17 18gaia_agent = CodeAgent(19 model=openai_nano_model,20 tools=[fetch_webpage, DuckDuckGoSearchTool(), PythonInterpreterTool(), read_file_tool, get_youtube_transcript, transcribe_audio], # WikipediaSearchTool(), VisitWebpageTool(max_output_length=60000)21 max_steps=7,22 additional_authorized_imports=["requests", "bs4", "pandas", "numpy", "markdownify"]23)24 25class GAIA_Agent:26 def __init__(self):27 self.system_prompt = gaia_prompt28 self.agent = gaia_agent29 30 def __call__(self, question: str) -> str:31 32 try:33 34 full_context = self.system_prompt + "\nTHE QUESTION:\n" + question35 36 final_answer = self.agent.run(full_context)37 print(f"final answer returned by agent ----> {final_answer}")38 return final_answer39 except Exception as e:40 error = f"An error occurred while processing the question: {e}"41 print(error)42 return error43 44# build context + append instructions and all45 46# clean answer function47 48if __name__ == "__main__":49 answer = gaia_agent.run(50 """51 You are a general AI assistant. I will ask you a question. You can answer with the following template:[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. Remember: GAIA requires exact answer matching. Just provide the factual answer.52 53 How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."""54 )55 pass