FD900's picture
Update agent.py
a1a42c2 verified
raw
history blame
1.28 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.
Your task is to provide accurate, concise answers to each question using both the text of the question and any provided file content.
Only return the final answer. Do not include explanations, formatting, or phrases like "Answer:".
Be exact and to the point."""
def answer_question(question_obj):
try:
# Load file content if available
file_content = ""
if question_obj.get("file_path"):
file_content = load_file_if_any(question_obj["file_path"])
# Compose user prompt
user_prompt = f"""Question:
{question_obj['question']}
Attached file content (if any):
{file_content}
Final answer:"""
# Call OpenAI
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)}"