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())
|