Spaces:
Sleeping
Sleeping
| """ | |
| Example usage of the GAIA agent with database search integration. | |
| This shows how the system works with the Supabase database. | |
| """ | |
| import os | |
| import sys | |
| # Add parent directory to path for imports | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from agent import answer_gaia_question | |
| from tools.database_tools import get_retriever | |
| def test_database_integration(): | |
| """Test the database search functionality.""" | |
| # Test questions similar to your database examples | |
| test_questions = [ | |
| # Similar to your Nature/statistical significance question | |
| "How many papers published by Science in 2020 would be incorrect if they used p-value of 0.03?", | |
| # Similar to your fish/invasive species question | |
| "What species from Finding Nemo has been found as invasive in Florida waters?", | |
| # Similar to your AI regulation question | |
| "What paper about AI ethics was submitted to arXiv in 2022?", | |
| # A completely different question | |
| "What is the capital of France?" | |
| ] | |
| print("π§ͺ Testing Database Integration\n") | |
| for i, question in enumerate(test_questions, 1): | |
| print(f"Test {i}: {question}") | |
| print("-" * 60) | |
| # Test similarity search directly | |
| try: | |
| retriever = get_retriever() | |
| similar_questions = retriever.search_similar_questions_manual(question, top_k=2, similarity_threshold=0.7) | |
| if similar_questions: | |
| print(f"β Found {len(similar_questions)} similar questions:") | |
| for j, sim_q in enumerate(similar_questions, 1): | |
| print(f" {j}. Similarity: {sim_q['similarity']:.3f}") | |
| print(f" Q: {sim_q['question'][:100]}...") | |
| print(f" A: {sim_q['answer']}") | |
| print() | |
| else: | |
| print("β No similar questions found") | |
| print() | |
| # Test full agent processing | |
| print("π€ Agent Processing:") | |
| answer = answer_gaia_question(question) | |
| print(f"Agent Answer: {answer}") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| print("=" * 80) | |
| print() | |
| def setup_environment(): | |
| """Check if all required environment variables are set.""" | |
| required_vars = ["OPENAI_API_KEY", "SUPABASE_URL", "SUPABASE_SERVICE_KEY"] | |
| missing_vars = [var for var in required_vars if not os.getenv(var)] | |
| if missing_vars: | |
| print(f"β Missing environment variables: {', '.join(missing_vars)}") | |
| print("Please add them to your .env file:") | |
| for var in missing_vars: | |
| print(f" {var}=your_value_here") | |
| return False | |
| print("β All environment variables are set") | |
| return True | |
| if __name__ == "__main__": | |
| print("π GAIA Agent Database Integration Test") | |
| print("=" * 50) | |
| if setup_environment(): | |
| test_database_integration() | |
| else: | |
| print("Please set up your environment variables first.") | |