File size: 1,973 Bytes
cc6f511
 
e222391
 
 
4bea841
e222391
 
 
cc6f511
 
 
 
 
e222391
cc6f511
 
 
 
4bea841
cc6f511
 
 
e222391
4bea841
 
 
 
 
e222391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Runner for Agents to output answers"""

import pandas as pd

from agents.basic_agent import BasicAgent
from prompts import get_better_task_statement

agent = BasicAgent()


def get_answer_payload_results_log(questions_data: dict) -> tuple:
    """Get Answer Payload, Results Log or Error Message"""
    results_log = []
    answers_payload = []
    print(f"Running agent on {len(questions_data)} questions...")

    for item in questions_data:
        task_id = item.get("task_id")
        question_text = item.get("question")
        file_name = item.get("file_name")
        if not task_id or question_text is None:
            print(f"Skipping item with missing task_id or question: {item}")
            continue
        try:
            if file_name:
                task_statement = get_better_task_statement(question_text, file_name)
            else:
                task_statement = get_better_task_statement(question_text)
            submitted_answer = agent(task_statement)
            answers_payload.append(
                {"task_id": task_id, "submitted_answer": submitted_answer}
            )
            results_log.append(
                {
                    "Task ID": task_id,
                    "Question": question_text,
                    "Submitted Answer": submitted_answer,
                }
            )
        except Exception as e:  # pylint: disable=broad-exception-caught
            print(f"Error running agent on task {task_id}: {e}")
            results_log.append(
                {
                    "Task ID": task_id,
                    "Question": question_text,
                    "Submitted Answer": f"AGENT ERROR: {e}",
                }
            )
    results_df = pd.DataFrame(results_log)

    if not answers_payload:
        error_message = "Agent did not produce any answers to submit."
        print(error_message)
        return None, results_df, error_message

    return answers_payload, results_df, None