Spaces:
Runtime error
Runtime error
added system prompt
Browse files
agent.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
from smolagents import CodeAgent, tool, OpenAIServerModel
|
@@ -48,16 +49,40 @@ def submit_answers(username: str, agent_code: str, answers: list) -> dict:
|
|
48 |
|
49 |
def create_agent() -> CodeAgent:
|
50 |
"""
|
51 |
-
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo
|
|
|
52 |
Requires OPENAI_API_KEY in the environment.
|
53 |
-
|
54 |
-
Returns:
|
55 |
-
CodeAgent: Configured with GAIA tools.
|
56 |
"""
|
|
|
57 |
model = OpenAIServerModel(model_id="gpt-3.5-turbo")
|
|
|
58 |
agent = CodeAgent(
|
59 |
tools=[fetch_questions, fetch_random_question, submit_answers],
|
60 |
model=model
|
61 |
-
# Use CodeAgent's built-in prompt handling
|
62 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
return agent
|
|
|
|
1 |
+
|
2 |
import os
|
3 |
import requests
|
4 |
from smolagents import CodeAgent, tool, OpenAIServerModel
|
|
|
49 |
|
50 |
def create_agent() -> CodeAgent:
|
51 |
"""
|
52 |
+
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo,
|
53 |
+
with a few-shot system prompt tailored to GAIA Level-1 exact-match requirements.
|
54 |
Requires OPENAI_API_KEY in the environment.
|
|
|
|
|
|
|
55 |
"""
|
56 |
+
# 1. Instantiate model
|
57 |
model = OpenAIServerModel(model_id="gpt-3.5-turbo")
|
58 |
+
# 2. Create the agent with default prompt
|
59 |
agent = CodeAgent(
|
60 |
tools=[fetch_questions, fetch_random_question, submit_answers],
|
61 |
model=model
|
|
|
62 |
)
|
63 |
+
# 3. Override its system prompt to include paper’s instructions + few-shot
|
64 |
+
agent.system_prompt_template = """
|
65 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
66 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
67 |
+
|
68 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
69 |
+
- If you are asked for a number, don't use commas, symbols or units (e.g. %, $, km) unless explicitly asked.
|
70 |
+
- If you are asked for a string, don't use articles ("a", "the"), abbreviations (e.g. "NYC"), or extra words; write digits in plain text unless specified otherwise.
|
71 |
+
- If you are asked for a comma separated list, apply the above rules to each element.
|
72 |
+
|
73 |
+
Example 1:
|
74 |
+
Question: What is 2 + 2?
|
75 |
+
Thought: simple arithmetic
|
76 |
+
FINAL ANSWER: 4
|
77 |
+
|
78 |
+
Example 2:
|
79 |
+
Question: What is the capital of France?
|
80 |
+
Thought: common geography
|
81 |
+
FINAL ANSWER: Paris
|
82 |
+
|
83 |
+
Now it’s your turn.
|
84 |
+
Question: {task}
|
85 |
+
"""
|
86 |
+
|
87 |
return agent
|
88 |
+
|