Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,18 +4,18 @@ import requests
|
|
4 |
import pandas as pd
|
5 |
|
6 |
from tools import AnswerTool
|
7 |
-
from smolagents import CodeAgent
|
8 |
|
9 |
# --- Constants ---
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
class BasicAgent:
|
13 |
def __init__(self):
|
14 |
-
#
|
|
|
15 |
answer_tool = AnswerTool()
|
16 |
-
# Initialize CodeAgent with only the AnswerTool, no code execution
|
17 |
self.agent = CodeAgent(
|
18 |
-
model=
|
19 |
tools=[answer_tool],
|
20 |
add_base_tools=False,
|
21 |
max_steps=1,
|
@@ -23,7 +23,7 @@ class BasicAgent:
|
|
23 |
)
|
24 |
|
25 |
def __call__(self, question: str) -> str:
|
26 |
-
#
|
27 |
return self.agent.run(question)
|
28 |
|
29 |
|
@@ -32,21 +32,14 @@ def run_and_submit_all(username):
|
|
32 |
if not username:
|
33 |
return "Please enter your Hugging Face username.", None
|
34 |
|
35 |
-
|
36 |
try:
|
37 |
resp = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15)
|
38 |
-
# Handle rate limiting specifically
|
39 |
if resp.status_code == 429:
|
40 |
return "Server rate limited the requests. Please wait a moment and try again.", None
|
41 |
resp.raise_for_status()
|
42 |
questions = resp.json()
|
43 |
-
except
|
44 |
-
# Specific HTTP errors not caught above
|
45 |
-
status_code = getattr(e.response, 'status_code', None)
|
46 |
-
if status_code == 429:
|
47 |
-
return "Server rate limited the requests. Please wait a moment and try again.", None
|
48 |
-
return f"Error fetching questions: {e}", None
|
49 |
-
except requests.exceptions.RequestException as e:
|
50 |
return f"Error fetching questions: {e}", None
|
51 |
|
52 |
# Run agent on all questions
|
|
|
4 |
import pandas as pd
|
5 |
|
6 |
from tools import AnswerTool
|
7 |
+
from smolagents import CodeAgent, OpenAIServerModel
|
8 |
|
9 |
# --- Constants ---
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
class BasicAgent:
|
13 |
def __init__(self):
|
14 |
+
# Initialize CodeAgent with an OpenAI model and custom AnswerTool
|
15 |
+
model = OpenAIServerModel(model_id="gpt-3.5-turbo")
|
16 |
answer_tool = AnswerTool()
|
|
|
17 |
self.agent = CodeAgent(
|
18 |
+
model=model,
|
19 |
tools=[answer_tool],
|
20 |
add_base_tools=False,
|
21 |
max_steps=1,
|
|
|
23 |
)
|
24 |
|
25 |
def __call__(self, question: str) -> str:
|
26 |
+
# Execute a single step to call the AnswerTool
|
27 |
return self.agent.run(question)
|
28 |
|
29 |
|
|
|
32 |
if not username:
|
33 |
return "Please enter your Hugging Face username.", None
|
34 |
|
35 |
+
# Fetch questions
|
36 |
try:
|
37 |
resp = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15)
|
|
|
38 |
if resp.status_code == 429:
|
39 |
return "Server rate limited the requests. Please wait a moment and try again.", None
|
40 |
resp.raise_for_status()
|
41 |
questions = resp.json()
|
42 |
+
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return f"Error fetching questions: {e}", None
|
44 |
|
45 |
# Run agent on all questions
|