Spaces:
Sleeping
Sleeping
File size: 1,149 Bytes
a72497b 85a8961 a72497b 85a8961 a72497b 5e71863 85a8961 a72497b 85a8961 5e71863 85a8961 5e71863 a72497b 85a8961 a72497b 85a8961 a72497b 85a8961 a72497b 85a8961 | 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 | 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)}" |