Spaces:
Runtime error
Runtime error
Mike Jay
commited on
Commit
·
e222391
1
Parent(s):
cc6f511
wip basic agent works
Browse files- agents/basic_agent.py +14 -0
- app.py +2 -4
- payload.py +36 -12
agents/basic_agent.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Base Agent"""
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class BasicAgent: # pylint: disable=too-few-public-methods
|
| 5 |
+
"""Base Agent for Evaluation"""
|
| 6 |
+
|
| 7 |
+
def __init__(self):
|
| 8 |
+
print("BasicAgent initialized.")
|
| 9 |
+
|
| 10 |
+
def __call__(self, question: str) -> str:
|
| 11 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 12 |
+
fixed_answer = "This is a default answer."
|
| 13 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 14 |
+
return fixed_answer
|
app.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
-
import pandas as pd
|
| 6 |
|
| 7 |
from questions import get_questions_data
|
| 8 |
from submit import submit_answers
|
|
@@ -53,11 +52,11 @@ def run_and_submit_all(
|
|
| 53 |
return "Questions list is empty or invalid format.", None
|
| 54 |
print(f"Retrieved {len(questions_data)} questions.")
|
| 55 |
|
| 56 |
-
answers_payload,
|
| 57 |
questions_data=questions_data
|
| 58 |
)
|
| 59 |
if error_message:
|
| 60 |
-
return error_message,
|
| 61 |
|
| 62 |
submission_data = {
|
| 63 |
"username": username.strip(),
|
|
@@ -66,7 +65,6 @@ def run_and_submit_all(
|
|
| 66 |
}
|
| 67 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..." # pylint: disable=line-too-long
|
| 68 |
print(status_update)
|
| 69 |
-
results_df = pd.DataFrame(results_log)
|
| 70 |
print(f"Submitting {len(answers_payload)} answers to: {SUBMIT_URL}")
|
| 71 |
|
| 72 |
if SAFETY_OFF:
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
from questions import get_questions_data
|
| 7 |
from submit import submit_answers
|
|
|
|
| 52 |
return "Questions list is empty or invalid format.", None
|
| 53 |
print(f"Retrieved {len(questions_data)} questions.")
|
| 54 |
|
| 55 |
+
answers_payload, results_df, error_message = get_answer_payload_results_log(
|
| 56 |
questions_data=questions_data
|
| 57 |
)
|
| 58 |
if error_message:
|
| 59 |
+
return error_message, results_df
|
| 60 |
|
| 61 |
submission_data = {
|
| 62 |
"username": username.strip(),
|
|
|
|
| 65 |
}
|
| 66 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..." # pylint: disable=line-too-long
|
| 67 |
print(status_update)
|
|
|
|
| 68 |
print(f"Submitting {len(answers_payload)} answers to: {SUBMIT_URL}")
|
| 69 |
|
| 70 |
if SAFETY_OFF:
|
payload.py
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
"""Runner for Agents to output answers"""
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def get_answer_payload_results_log(questions_data: dict) -> tuple:
|
| 5 |
"""Get Answer Payload, Results Log or Error Message"""
|
| 6 |
results_log = []
|
| 7 |
answers_payload = []
|
| 8 |
-
|
| 9 |
|
| 10 |
for item in questions_data:
|
| 11 |
task_id = item.get("task_id")
|
|
@@ -13,14 +19,32 @@ def get_answer_payload_results_log(questions_data: dict) -> tuple:
|
|
| 13 |
if not task_id or question_text is None:
|
| 14 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 15 |
continue
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""Runner for Agents to output answers"""
|
| 2 |
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
from agents.basic_agent import BasicAgent
|
| 6 |
+
|
| 7 |
+
agent = BasicAgent()
|
| 8 |
+
|
| 9 |
|
| 10 |
def get_answer_payload_results_log(questions_data: dict) -> tuple:
|
| 11 |
"""Get Answer Payload, Results Log or Error Message"""
|
| 12 |
results_log = []
|
| 13 |
answers_payload = []
|
| 14 |
+
print(f"Running agent on {len(questions_data)} questions...")
|
| 15 |
|
| 16 |
for item in questions_data:
|
| 17 |
task_id = item.get("task_id")
|
|
|
|
| 19 |
if not task_id or question_text is None:
|
| 20 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 21 |
continue
|
| 22 |
+
try:
|
| 23 |
+
submitted_answer = agent(question_text)
|
| 24 |
+
answers_payload.append(
|
| 25 |
+
{"task_id": task_id, "submitted_answer": submitted_answer}
|
| 26 |
+
)
|
| 27 |
+
results_log.append(
|
| 28 |
+
{
|
| 29 |
+
"Task ID": task_id,
|
| 30 |
+
"Question": question_text,
|
| 31 |
+
"Submitted Answer": submitted_answer,
|
| 32 |
+
}
|
| 33 |
+
)
|
| 34 |
+
except Exception as e: # pylint: disable=broad-exception-caught
|
| 35 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 36 |
+
results_log.append(
|
| 37 |
+
{
|
| 38 |
+
"Task ID": task_id,
|
| 39 |
+
"Question": question_text,
|
| 40 |
+
"Submitted Answer": f"AGENT ERROR: {e}",
|
| 41 |
+
}
|
| 42 |
+
)
|
| 43 |
+
results_df = pd.DataFrame(results_log)
|
| 44 |
+
|
| 45 |
+
if not answers_payload:
|
| 46 |
+
error_message = "Agent did not produce any answers to submit."
|
| 47 |
+
print(error_message)
|
| 48 |
+
return None, results_df, error_message
|
| 49 |
+
|
| 50 |
+
return answers_payload, results_df, None
|