Spaces:
Paused

File size: 3,284 Bytes
b5594ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
Diagnostic script for Gemini integration issues.
Helps identify configuration and dependency problems.
"""
import sys
import os

# Add project root to path
sys.path.insert(0, os.getcwd())

from core.config import get_settings
import logging

logging.basicConfig(level=logging.DEBUG, format='%(name)s - %(levelname)s - %(message)s')

def diagnose_gemini():
    """Run comprehensive Gemini diagnostics."""
    settings = get_settings()
    
    print("\n" + "="*60)
    print("NEXUS AI - GEMINI INTEGRATION DIAGNOSTICS")
    print("="*60)
    
    # 1. Check Configuration
    print("\n[1/4] Configuration Check")
    print(f"  Primary Provider: {settings.AI_PRIMARY_PROVIDER}")
    print(f"  Primary Model: {settings.AI_MODEL}")
    print(f"  Fast Model: {settings.AI_FAST_MODEL}")
    print(f"  Secondary Provider: {settings.AI_SECONDARY_PROVIDER}")
    print(f"  Backup Model: {settings.AI_BACKUP_PROVIDER_MODEL}")
    
    # 2. Check API Key
    print("\n[2/4] API Key Check")
    if not settings.GOOGLE_API_KEY:
        print("  ❌ GOOGLE_API_KEY: NOT SET")
        print("     β†’ Set GOOGLE_API_KEY environment variable")
        print("     β†’ Get key from: https://aistudio.google.com/app/apikeys")
    else:
        key_preview = f"{settings.GOOGLE_API_KEY[:10]}...{settings.GOOGLE_API_KEY[-5:]}"
        print(f"  βœ… GOOGLE_API_KEY: SET ({key_preview}) [length={len(settings.GOOGLE_API_KEY)}]")
    
    # 3. Check Dependencies
    print("\n[3/4] Dependency Check")
    dependencies = {
        "langchain_google_genai": "LangChain Google AI integration",
        "langchain_core": "LangChain core",
        "google.generativeai": "Google Generative AI SDK",
    }
    
    for module_name, description in dependencies.items():
        try:
            __import__(module_name)
            print(f"  βœ… {module_name}: installed ({description})")
        except ImportError as e:
            print(f"  ❌ {module_name}: NOT installed ({description})")
            print(f"     β†’ Install with: pip install {module_name.split('.')[0]}")
    
    # 4. Test Initialization
    print("\n[4/4] Initialization Test")
    try:
        from core.llm import get_llm
        print("  ⏳ Attempting to initialize Google Gemini...")
        
        llm = get_llm(provider="google", model="gemini-2.5-flash")
        print(f"  βœ… Initialization successful!")
        print(f"     β†’ Model: {getattr(llm, 'model', 'unknown')}")
        
        # Test a simple invocation
        print("  ⏳ Testing model invocation...")
        response = llm.invoke("Say 'Gemini is working!' in one sentence.")
        print(f"  βœ… Model response: {response.content[:100]}...")
        
    except ImportError as e:
        print(f"  ❌ Import Error: {e}")
        print(f"     β†’ Missing dependency. Check [3/4] above.")
    except ValueError as e:
        print(f"  ❌ Configuration Error: {e}")
        print(f"     β†’ Check API key and configuration")
    except Exception as e:
        print(f"  ❌ Initialization Failed: {type(e).__name__}: {e}")
        print(f"     β†’ Check logs for detailed error information")
    
    print("\n" + "="*60)
    print("Diagnostics Complete")
    print("="*60 + "\n")

if __name__ == "__main__":
    diagnose_gemini()