FD900's picture
Update agent.py
85a8961 verified
raw
history blame
1.17 kB
import os
from openai import OpenAI
from tools.file_loader import load_file_if_any
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
SYSTEM_PROMPT = """You are an advanced AI agent participating in the GAIA benchmark.
For each question, read the text and any attached file, then provide a concise and accurate final answer.
Only return the answer itself — no explanations or formatting."""
def answer_question(question_obj):
try:
# Load any attached file content
file_content = ""
if question_obj.get("file_path"):
file_content = load_file_if_any(question_obj["file_path"])
user_prompt = f"""Question:
{question_obj['question']}
Attached file content (if any):
{file_content}
Final answer:"""
# Call OpenAI GPT-4
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_prompt}
]
)
return response.choices[0].message.content.strip()
except Exception as e:
return f"[ERROR] Failed to answer: {str(e)}"