ira/test_ui_search.py

56 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Test script for the UI search functionality.
This script tests the search functionality of the UI without launching the Gradio interface.
"""
import os
import json
from pathlib import Path
from ui.gradio_interface import GradioInterface
def main():
"""Main function to test the UI search functionality."""
# Create the interface
interface = GradioInterface()
# Test queries
test_queries = [
"What are the latest advancements in quantum computing?",
"Compare transformer and RNN architectures for NLP tasks",
"Explain the environmental impact of electric vehicles"
]
# Test each query
for query in test_queries:
print(f"\n\n{'=' * 80}")
print(f"Testing query: {query}")
print(f"{'=' * 80}\n")
# Process the query
markdown_results, results_file = interface.process_query(query, num_results=5)
# Print the results
print(f"\nResults file: {results_file}")
print(f"\nMarkdown results preview:")
print(f"{markdown_results[:500]}...\n")
# Check if results file exists and has content
if results_file and os.path.exists(results_file):
with open(results_file, 'r') as f:
results = json.load(f)
print(f"Number of results: {len(results)}")
if len(results) > 0:
print(f"First result title: {results[0].get('title', 'No title')}")
print(f"First result URL: {results[0].get('url', 'No URL')}")
else:
print("No results file or empty results.")
print("\nTest completed.")
if __name__ == "__main__":
main()