import sys import os # Add the project root to sys.path to allow core imports sys.path.append(os.getcwd()) from core.config import get_settings from core.llm import get_llm, get_text_embeddings def test_gemini_integration(): """ Diagnostic script to verify Google Gemini LLM and Embedding configuration. Specifically checks for the 768-dimension requirement for text embeddings. """ settings = get_settings() print("\n--- NEXUS AI: GEMINI DIAGNOSTIC ---") print(f"Project: {settings.APP_NAME}") print(f"Provider: {settings.AI_PROVIDER}") print(f"LLM Model: {settings.AI_MODEL}") print(f"Embedding: {settings.AI_TEXT_EMBEDDING_MODEL}") if not settings.GOOGLE_API_KEY: print("\n[!] ERROR: GOOGLE_API_KEY is missing from your .env file.") return # 1. Test LLM Reasoning print("\n[1/2] Testing LLM Reasoning (gemini-3-flash-preview)...") try: llm = get_llm() response = llm.invoke("Hello Nexus. Briefly state your purpose for this hackathon.") print(f"Response: {response.content}") print("✅ LLM Connectivity: SUCCESS") except Exception as e: print(f"❌ LLM Connectivity: FAILED\nDetail: {str(e)}") # 2. Test Text Embeddings (MRL 768) print("\n[2/2] Testing Text Embeddings (MRL 768 Dimensions)...") try: embed_model = get_text_embeddings() sample_text = "Optimizing hybrid embedding infrastructure for free-tier deployment." vector = embed_model.embed_query(sample_text) dim = len(vector) print(f"Vector Dimensions: {dim}") if dim == 768: print("✅ Embedding Compatibility: SUCCESS (768-D Match)") else: print(f"⚠️ Embedding Compatibility: WARNING (Got {dim}-D, Expected 768-D)") print("Check if models/gemini-embedding-001 supports output_dimensionality in your region.") except Exception as e: print(f"❌ Embedding Connectivity: FAILED\nDetail: {str(e)}") print("\n--- DIAGNOSTIC COMPLETE ---\n") if __name__ == "__main__": test_gemini_integration()