File size: 1,681 Bytes
cc6f511
 
e222391
 
 
 
 
 
cc6f511
 
 
 
 
e222391
cc6f511
 
 
 
 
 
 
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
"""Runner for Agents to output answers"""

import pandas as pd

from agents.basic_agent import BasicAgent

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")
        if not task_id or question_text is None:
            print(f"Skipping item with missing task_id or question: {item}")
            continue
        try:
            submitted_answer = agent(question_text)
            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