File size: 1,436 Bytes
e0f9aaf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# test_agents,py
import os
from dotenv import load_dotenv

# Import the BasicAgent from your app module
try:
    from app import BasicAgent
except ImportError as e:
    print(f"Error importing BasicAgent from app.py: {e}")
    print("Please ensure app.py is in the same directory or accessible in the Python path.")
    exit(1)

# --- Define Question-Answer Pairs ---
# Note: The 'A' part is just for reference here; the agent will generate its own answer.
QA_PAIRS = {
    "What is the capital of France?": "Paris",
    "Who wrote 'Hamlet'?": "William Shakespeare",
    "What is the formula for water?": "H2O",
    "How does photosynthesis work?": "Plants use sunlight, water, and carbon dioxide to create their own food.",
    # Agent should find current data
    "What is the current population of Earth?": "Approximately 8 billion",
}


def run_test_questions():
    """Instantiates the agent and runs it on the predefined questions."""
    print("--- Starting Agent Test ---")
    # Load environment variables (needed for BasicAgent initialization)
    load_dotenv()
    print(f"HF_TOKEN found: {'Yes' if os.getenv('HF_TOKEN') else 'No'}")

    agent = BasicAgent()

    for question in QA_PAIRS.keys():
        print(f"\n--- Testing Question ---")
        print(f"Q: {question}")
        answer = agent(question)  # Call the agent instance
        print(f"Agent A: {answer}")


if __name__ == "__main__":
    run_test_questions()