File size: 5,336 Bytes
7644eac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
Quick test script to verify setup is working correctly.
Run this after installing dependencies.
"""

import sys
import os

def test_imports():
    """Test that all critical imports work."""
    print("πŸ” Testing imports...")
    
    try:
        import flask
        print("  βœ… Flask")
    except ImportError as e:
        print(f"  ❌ Flask: {e}")
        return False
    
    try:
        import pydantic
        print(f"  βœ… Pydantic (version {pydantic.VERSION})")
        if pydantic.VERSION.startswith("2"):
            print("  ⚠️  WARNING: Pydantic v2 detected, should be v1.10.18")
    except ImportError as e:
        print(f"  ❌ Pydantic: {e}")
        return False
    
    try:
        from langchain.chat_models import ChatOpenAI
        print("  βœ… LangChain ChatOpenAI")
    except ImportError as e:
        print(f"  ❌ LangChain ChatOpenAI: {e}")
        return False
    
    try:
        from dotenv import load_dotenv
        print("  βœ… python-dotenv")
    except ImportError as e:
        print(f"  ❌ python-dotenv: {e}")
        return False
    
    try:
        from flask_sqlalchemy import SQLAlchemy
        print("  βœ… Flask-SQLAlchemy")
    except ImportError as e:
        print(f"  ❌ Flask-SQLAlchemy: {e}")
        return False
    
    return True


def test_env_file():
    """Test that .env file exists and has required keys."""
    print("\nπŸ” Testing environment configuration...")
    
    from dotenv import load_dotenv
    
    env_path = os.path.join(os.path.dirname(__file__), '.env')
    
    if not os.path.exists(env_path):
        print("  ❌ .env file not found!")
        print("  πŸ“ Create .env file and add OPENAI_API_KEY")
        return False
    
    print(f"  βœ… .env file exists at: {env_path}")
    
    load_dotenv(env_path)
    
    openai_key = os.getenv('OPENAI_API_KEY')
    if not openai_key:
        print("  ❌ OPENAI_API_KEY not set in .env")
        return False
    
    if openai_key.startswith('sk-'):
        print("  βœ… OPENAI_API_KEY is set")
    else:
        print("  ⚠️  OPENAI_API_KEY format looks incorrect")
    
    return True


def test_database():
    """Test database connection."""
    print("\nπŸ” Testing database...")
    
    db_path = os.path.join(os.path.dirname(__file__), 'learning_path.db')
    
    if os.path.exists(db_path):
        print(f"  βœ… Database exists at: {db_path}")
        return True
    else:
        print("  ⚠️  Database not found (will be created on first run)")
        print("  πŸ’‘ Run: python -m migrations.add_chatbot_tables")
        return True


def test_project_structure():
    """Test that key files and directories exist."""
    print("\nπŸ” Testing project structure...")
    
    required_paths = [
        'src',
        'src/learning_path.py',
        'src/ml',
        'src/ml/model_orchestrator.py',
        'src/services',
        'web_app',
        'run_flask.py',
        'requirements.txt'
    ]
    
    all_exist = True
    for path in required_paths:
        full_path = os.path.join(os.path.dirname(__file__), path)
        if os.path.exists(full_path):
            print(f"  βœ… {path}")
        else:
            print(f"  ❌ {path} not found")
            all_exist = False
    
    return all_exist


def test_few_shot_prompting():
    """Test that few-shot prompting code is in place."""
    print("\nπŸ” Testing few-shot prompting implementation...")
    
    learning_path_file = os.path.join(os.path.dirname(__file__), 'src', 'learning_path.py')
    
    try:
        with open(learning_path_file, 'r', encoding='utf-8') as f:
            content = f.read()
        
        if '=== EXAMPLE 1:' in content and '=== EXAMPLE 2:' in content:
            print("  βœ… Few-shot prompting examples found")
            return True
        else:
            print("  ❌ Few-shot prompting examples not found")
            return False
    except Exception as e:
        print(f"  ❌ Error reading learning_path.py: {e}")
        return False


def main():
    """Run all tests."""
    print("=" * 60)
    print("πŸš€ AI Learning Path Generator - Setup Verification")
    print("=" * 60)
    
    results = []
    
    results.append(("Imports", test_imports()))
    results.append(("Environment", test_env_file()))
    results.append(("Database", test_database()))
    results.append(("Project Structure", test_project_structure()))
    results.append(("Few-Shot Prompting", test_few_shot_prompting()))
    
    print("\n" + "=" * 60)
    print("πŸ“Š Test Results Summary")
    print("=" * 60)
    
    all_passed = True
    for test_name, passed in results:
        status = "βœ… PASS" if passed else "❌ FAIL"
        print(f"{status}: {test_name}")
        if not passed:
            all_passed = False
    
    print("=" * 60)
    
    if all_passed:
        print("\nπŸŽ‰ All tests passed! Your setup is ready.")
        print("\nπŸ“ Next steps:")
        print("   1. Run: python run_flask.py")
        print("   2. Open: http://localhost:5000")
        print("   3. Test the application")
    else:
        print("\n⚠️  Some tests failed. Please fix the issues above.")
        print("\nπŸ“š See LOCAL_SETUP_GUIDE.md for detailed instructions")
    
    return 0 if all_passed else 1


if __name__ == "__main__":
    sys.exit(main())