Spaces:
Sleeping
Sleeping
File size: 3,675 Bytes
396f5a0 |
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 |
from dotenv import load_dotenv
from smolagents import CodeAgent
from smolagents import OpenAIServerModel
from tool import fetch_webpage, read_file_tool, get_youtube_transcript
from smolagents import VisitWebpageTool, WikipediaSearchTool, PythonInterpreterTool, DuckDuckGoSearchTool, WebSearchTool, SpeechToTextTool
from prompt import gaia_prompt
load_dotenv()
openai_nano_model = OpenAIServerModel(
model_id="gpt-4.1-nano-2025-04-14",
# model_id="o3-mini-2025-01-31",
)
gaia_agent = CodeAgent(
model=openai_nano_model,
tools=[fetch_webpage, DuckDuckGoSearchTool(), PythonInterpreterTool(), read_file_tool, get_youtube_transcript], # WikipediaSearchTool(), VisitWebpageTool(max_output_length=60000)
max_steps=5,
verbosity_level=2,
additional_authorized_imports=["requests", "bs4", "pandas", "numpy", "markdownify"]
)
class GAIA_Agent:
def __init__(self):
self.system_prompt = gaia_prompt
self.agent = gaia_agent
def __call__(self, question: str) -> str:
try:
full_context = self.system_prompt + "\nTHE QUESTION:\n" + question
final_answer = self.agent.run(full_context)
return final_answer
except Exception as e:
error = f"An error occurred while processing the question: {e}"
print(error)
return error
# build context + append instructions and all
# clean answer function
if __name__ == "__main__":
pass
# gaia_agent.run("What is the weather in Mumbai?")
# answer = gaia_agent.run(
# f"""
# 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.
# How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.
# """
# )
# print(gaia_prompt)
# answer = gaia_agent.run("""
# 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.
# You can search for results and then visit a webpage to get more information. Break down the problem into smaller sub-problems and solve them one by one.
# Think like a human.
# What is the final numeric output from the attached Python code?
# ----
# """)
# print(f"this is the final answer the gaia agent gave ---> {answer}") |