Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: Add test file for Google PSE integration

hashedvikingdb238d333635
diff --git a/tests/test_google_pse.py b/tests/test_google_pse.py
new file mode 100644
index 0000000000..6a6baa62da
--- /dev/null
+++ b/tests/test_google_pse.py
@@ -0,0 +1,89 @@
+"""
+Test script for Google Programmable Search Engine integration.
+Run this script to verify that your Google PSE API key and search engine ID are working.
+"""
+
+import os
+import sys
+from dotenv import load_dotenv
+
+# Load environment variables from .env file
+load_dotenv()
+
+# Add parent directory to path to import modules
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from web_search_engines.search_engine_factory import create_search_engine
+from config import get_llm
+
+def test_google_pse_search():
+ """Test Google PSE search engine"""
+ print("Testing Google Programmable Search Engine...")
+
+ # Check if API key and search engine ID are set
+ api_key = os.getenv("GOOGLE_PSE_API_KEY")
+ search_engine_id = os.getenv("GOOGLE_PSE_ENGINE_ID")
+
+ if not api_key:
+ print("❌ GOOGLE_PSE_API_KEY not set in environment variables")
+ return False
+
+ if not search_engine_id:
+ print("❌ GOOGLE_PSE_ENGINE_ID not set in environment variables")
+ return False
+
+ print("✅ API key and search engine ID found")
+
+ try:
+ # Create search engine
+ engine = create_search_engine(
+ "google_pse",
+ llm=get_llm(),
+ max_results=5,
+ region="us",
+ safe_search=True,
+ search_language="English"
+ )
+
+ if not engine:
+ print("❌ Failed to create Google PSE search engine")
+ return False
+
+ print("✅ Search engine created successfully")
+
+ # Run a simple test query
+ query = "artificial intelligence latest developments"
+ print(f"Running test query: '{query}'")
+
+ results = engine.run(query)
+
+ if not results:
+ print("❌ No results returned")
+ return False
+
+ print(f"✅ {len(results)} results returned")
+
+ # Print the first result
+ print("\nFirst result:")
+ first_result = results[0]
+ print(f"Title: {first_result['title']}")
+ print(f"URL: {first_result['url']}")
+ print(f"Snippet: {first_result['snippet'][:100]}...")
+
+ return True
+
+ except Exception as e:
+ print(f"❌ Error: {str(e)}")
+ return False
+
+if __name__ == "__main__":
+ success = test_google_pse_search()
+ if success:
+ print("\n✅ Google Programmable Search Engine test completed successfully")
+ else:
+ print("\n❌ Google Programmable Search Engine test failed")
+ print("\nPlease check that:")
+ print("1. You have set GOOGLE_PSE_API_KEY and GOOGLE_PSE_ENGINE_ID in .env file")
+ print("2. The API key is valid and has not reached its quota")
+ print("3. The search engine ID is correct and the search engine is properly configured")
+ print("4. Your network connection allows access to Google APIs")
\ No newline at end of file