Spaces:
Sleeping
Sleeping
File size: 2,566 Bytes
5d9aa5e |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
"""
Test the MultiModalAgent.
"""
import os
import sys
import logging
import json
# Add the current directory to sys.path to import local modules
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import the MultiModalAgent
from agent import MultiModalAgent
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger('test_agent')
def main():
"""Test the MultiModalAgent with some sample questions."""
# Initialize the agent
resource_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resource')
agent = MultiModalAgent(resource_dir=resource_dir)
# Load test questions from metadata.jsonl
metadata_path = os.path.join(resource_dir, 'metadata.jsonl')
test_questions = []
with open(metadata_path, 'r', encoding='utf-8') as f:
for line in f:
entry = json.loads(line.strip())
if 'Question' in entry and 'file_name' in entry and entry['file_name']:
test_questions.append({
'task_id': entry.get('task_id'),
'question': entry['Question'],
'file_name': entry['file_name'],
'expected_answer': entry.get('Final answer')
})
if len(test_questions) >= 5: # Limit to 5 questions
break
# If no questions with files were found, use some generic questions
if not test_questions:
test_questions = [
{
'question': "What's the oldest Blu-Ray in the inventory spreadsheet?",
'file_name': None,
'expected_answer': None
},
{
'question': "How many files are in the resource directory?",
'file_name': None,
'expected_answer': None
}
]
# Test the agent with each question
for i, q in enumerate(test_questions):
question = q['question']
logger.info(f"Testing question {i+1}: {question}")
answer = agent(question)
logger.info(f"Answer: {answer}")
if q['expected_answer']:
logger.info(f"Expected answer: {q['expected_answer']}")
if answer.strip() == q['expected_answer'].strip():
logger.info("Correct answer!")
else:
logger.warning("Incorrect answer.")
logger.info("-" * 80)
if __name__ == "__main__":
main()
|