Final_Assignment_Template / test_agents,py
TzurVaich's picture
10% accurate, first working version
e0f9aaf
raw
history blame
1.44 kB
# 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()