Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,12 +15,16 @@ of numbers and/or strings. If you are asked for a number, don't use comma to wri
|
|
15 |
|
16 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
class MyAgent:
|
19 |
def __init__(self):
|
20 |
-
|
21 |
-
|
22 |
-
model_id="gpt-4",
|
23 |
-
system_message=SYSTEM_PROMPT
|
24 |
)
|
25 |
self.agent = CodeAgent(
|
26 |
tools=[DuckDuckGoSearchTool()],
|
@@ -28,13 +32,9 @@ class MyAgent:
|
|
28 |
)
|
29 |
|
30 |
def __call__(self, question: str) -> str:
|
31 |
-
# Run agent on the question
|
32 |
return self.agent.run(question)
|
33 |
|
34 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
35 |
-
"""
|
36 |
-
Fetches questions, runs the agent, submits answers, returns status and results table.
|
37 |
-
"""
|
38 |
space_id = os.getenv("SPACE_ID")
|
39 |
|
40 |
if profile:
|
|
|
15 |
|
16 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
17 |
|
18 |
+
# Custom model wrapper that injects system message
|
19 |
+
class PatchedOpenAIServerModel(OpenAIServerModel):
|
20 |
+
def generate(self, messages, *args, **kwargs):
|
21 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}] + messages
|
22 |
+
return super().generate(messages, *args, **kwargs)
|
23 |
+
|
24 |
class MyAgent:
|
25 |
def __init__(self):
|
26 |
+
self.model = PatchedOpenAIServerModel(
|
27 |
+
model_id="gpt-4" # system_message removed; injected manually
|
|
|
|
|
28 |
)
|
29 |
self.agent = CodeAgent(
|
30 |
tools=[DuckDuckGoSearchTool()],
|
|
|
32 |
)
|
33 |
|
34 |
def __call__(self, question: str) -> str:
|
|
|
35 |
return self.agent.run(question)
|
36 |
|
37 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
|
|
|
38 |
space_id = os.getenv("SPACE_ID")
|
39 |
|
40 |
if profile:
|