Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,9 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 19 |
|
| 20 |
class MyAgent:
|
| 21 |
def __init__(self):
|
| 22 |
-
#
|
| 23 |
self.model = OpenAIServerModel(
|
| 24 |
-
model_id="gpt-4"
|
| 25 |
-
system_prompt=SYSTEM_PROMPT
|
| 26 |
)
|
| 27 |
self.agent = CodeAgent(
|
| 28 |
tools=[DuckDuckGoSearchTool()],
|
|
@@ -30,13 +29,22 @@ class MyAgent:
|
|
| 30 |
)
|
| 31 |
|
| 32 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
try:
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
import traceback
|
| 37 |
traceback.print_exc()
|
| 38 |
return f"AGENT ERROR: {e}"
|
| 39 |
|
|
|
|
| 40 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 41 |
"""
|
| 42 |
Fetches questions, runs the agent, submits answers, returns status and results table.
|
|
|
|
| 19 |
|
| 20 |
class MyAgent:
|
| 21 |
def __init__(self):
|
| 22 |
+
# Initialize model WITHOUT system_message or system_prompt
|
| 23 |
self.model = OpenAIServerModel(
|
| 24 |
+
model_id="gpt-4"
|
|
|
|
| 25 |
)
|
| 26 |
self.agent = CodeAgent(
|
| 27 |
tools=[DuckDuckGoSearchTool()],
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
def __call__(self, question: str) -> str:
|
| 32 |
+
# Manually prepend system prompt in the messages for chat completion
|
| 33 |
+
messages = [
|
| 34 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 35 |
+
{"role": "user", "content": question}
|
| 36 |
+
]
|
| 37 |
try:
|
| 38 |
+
# Assuming your model supports a method like `complete` or `run` that accepts messages
|
| 39 |
+
# If your agent.run expects just the question string, you must use model.complete yourself.
|
| 40 |
+
# So call model.complete(messages=messages) instead:
|
| 41 |
+
return self.model.complete(messages=messages)
|
| 42 |
except Exception as e:
|
| 43 |
import traceback
|
| 44 |
traceback.print_exc()
|
| 45 |
return f"AGENT ERROR: {e}"
|
| 46 |
|
| 47 |
+
|
| 48 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 49 |
"""
|
| 50 |
Fetches questions, runs the agent, submits answers, returns status and results table.
|