relisora commited on
chore: write small script to test agent
Browse files- .gitignore +3 -0
- agent.py +9 -0
- app.py +2 -11
- evaluate_local.py +51 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
*$py.class
|
agent.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class BasicAgent:
|
| 2 |
+
def __init__(self):
|
| 3 |
+
print("BasicAgent initialized.")
|
| 4 |
+
|
| 5 |
+
def __call__(self, question: str) -> str:
|
| 6 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 7 |
+
fixed_answer = "This is a default answer."
|
| 8 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 9 |
+
return fixed_answer
|
app.py
CHANGED
|
@@ -4,21 +4,12 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
-
# --- Basic Agent Definition ---
|
| 12 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
class BasicAgent:
|
| 14 |
-
def __init__(self):
|
| 15 |
-
print("BasicAgent initialized.")
|
| 16 |
-
def __call__(self, question: str) -> str:
|
| 17 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
fixed_answer = "This is a default answer."
|
| 19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 20 |
-
return fixed_answer
|
| 21 |
-
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
| 24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from agent import BasicAgent
|
| 8 |
+
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 14 |
"""
|
| 15 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
evaluate_local.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run the assignment agent locally without submitting results."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
from agent import BasicAgent
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def main() -> None:
|
| 14 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 15 |
+
parser.add_argument(
|
| 16 |
+
"--limit",
|
| 17 |
+
type=int,
|
| 18 |
+
default=None,
|
| 19 |
+
help="Evaluate only the first N questions.",
|
| 20 |
+
)
|
| 21 |
+
args = parser.parse_args()
|
| 22 |
+
|
| 23 |
+
response = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15)
|
| 24 |
+
response.raise_for_status()
|
| 25 |
+
questions = response.json()
|
| 26 |
+
if args.limit is not None:
|
| 27 |
+
questions = questions[:args.limit]
|
| 28 |
+
|
| 29 |
+
agent = BasicAgent()
|
| 30 |
+
print(f"Evaluating {len(questions)} question(s) locally; nothing will be submitted.\n")
|
| 31 |
+
|
| 32 |
+
for index, item in enumerate(questions, start=1):
|
| 33 |
+
task_id = item.get("task_id")
|
| 34 |
+
question = item.get("question")
|
| 35 |
+
if not task_id or question is None:
|
| 36 |
+
print(f"[{index}] Skipping malformed question: {item}")
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
answer = agent(question)
|
| 41 |
+
except Exception as error:
|
| 42 |
+
print(f"[{index}] {task_id}: ERROR: {error}")
|
| 43 |
+
continue
|
| 44 |
+
|
| 45 |
+
print(f"[{index}] {task_id}")
|
| 46 |
+
print(f"Question: {question}")
|
| 47 |
+
print(f"Answer: {answer}\n")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
main()
|