FD900's picture
Update agent.py
5e71863 verified
raw
history blame
1.15 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:
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:"""
# ✅ Use GPT-3.5-turbo (free-tier)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
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)}"