Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,49 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
# If you're using tools like Bing search or SerpAPI, you can integrate them here.
|
| 5 |
-
# from tools.search import web_search
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
try:
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
if search_summary:
|
| 30 |
-
user_parts.append(f"Web search:\n{search_summary.strip()}")
|
| 31 |
-
user_parts.append(f"Question:\n{question}")
|
| 32 |
-
user_prompt = "\n\n".join(user_parts)
|
| 33 |
-
|
| 34 |
-
# Call GPT-4
|
| 35 |
-
response = openai.ChatCompletion.create(
|
| 36 |
model="gpt-4",
|
| 37 |
messages=[
|
| 38 |
-
{"role": "system", "content":
|
| 39 |
{"role": "user", "content": user_prompt}
|
| 40 |
-
]
|
| 41 |
-
temperature=0.2,
|
| 42 |
-
max_tokens=300
|
| 43 |
)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
return answer
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
-
return f"[ERROR] Failed to answer: {e}"
|
|
|
|
| 1 |
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
from tools.file_loader import load_file_if_any
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 6 |
|
| 7 |
+
SYSTEM_PROMPT = """You are an advanced AI agent participating in the GAIA benchmark.
|
| 8 |
+
For each question, read the text and any attached file, then provide a concise and accurate final answer.
|
| 9 |
+
Only return the answer itself — no explanations or formatting."""
|
| 10 |
+
|
| 11 |
+
def answer_question(question_obj):
|
| 12 |
try:
|
| 13 |
+
# Load any attached file content
|
| 14 |
+
file_content = ""
|
| 15 |
+
if question_obj.get("file_path"):
|
| 16 |
+
file_content = load_file_if_any(question_obj["file_path"])
|
| 17 |
+
|
| 18 |
+
user_prompt = f"""Question:
|
| 19 |
+
{question_obj['question']}
|
| 20 |
+
|
| 21 |
+
Attached file content (if any):
|
| 22 |
+
{file_content}
|
| 23 |
+
|
| 24 |
+
Final answer:"""
|
| 25 |
+
|
| 26 |
+
# Call OpenAI GPT-4
|
| 27 |
+
response = client.chat.completions.create(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
model="gpt-4",
|
| 29 |
messages=[
|
| 30 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 31 |
{"role": "user", "content": user_prompt}
|
| 32 |
+
]
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
+
return response.choices[0].message.content.strip()
|
|
|
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
+
return f"[ERROR] Failed to answer: {str(e)}"
|