forked from saikesav-sai/dripemails_web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_ai_features.py
More file actions
170 lines (150 loc) · 4.8 KB
/
verify_ai_features.py
File metadata and controls
170 lines (150 loc) · 4.8 KB
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
#!/usr/bin/env python
"""
Verification script for AI Email Features
Run this to verify all systems are operational
"""
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dripemails.settings')
django.setup()
print('=' * 70)
print(' AI EMAIL FEATURES - SYSTEM VERIFICATION')
print('=' * 70)
print()
all_good = True
# 1. Check imports
print('1. Checking Imports...')
try:
from campaigns.ai_utils import (
generate_email_content,
analyze_email_topics,
summarize_topics,
preprocess_text
)
print(' ✓ AI utilities module imports successfully')
except Exception as e:
print(f' ✗ AI utilities import failed: {e}')
all_good = False
try:
from campaigns.models import Campaign, Email, EmailAIAnalysis
print(' ✓ Models import successfully (EmailAIAnalysis included)')
except Exception as e:
print(f' ✗ Models import failed: {e}')
all_good = False
try:
from campaigns.views import (
generate_email_with_ai,
analyze_campaign_topics,
email_analysis_view,
campaign_analysis_view
)
print(' ✓ View functions import successfully')
except Exception as e:
print(f' ✗ Views import failed: {e}')
all_good = False
# 2. Check database model
print()
print('2. Checking Database...')
try:
from django.db import connection
from django.db.utils import OperationalError
cursor = connection.cursor()
try:
cursor.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='campaigns_emailaianalysis'"
)
result = cursor.fetchone()
if result:
print(' ✓ EmailAIAnalysis table exists in database')
else:
print(' ✗ EmailAIAnalysis table NOT found')
all_good = False
except Exception as e:
print(f' ✗ Database query failed: {e}')
all_good = False
except Exception as e:
print(f' ✗ Database connection failed: {e}')
all_good = False
# 3. Check dependencies
print()
print('3. Checking Dependencies...')
dependencies = {
'nltk': 'Natural Language Toolkit',
'gensim': 'Topic Modeling',
'openai': 'OpenAI API Client',
'pandas': 'Data Analysis'
}
for module_name, description in dependencies.items():
try:
__import__(module_name)
print(f' ✓ {module_name:15} ({description})')
except ImportError:
print(f' ✗ {module_name:15} NOT INSTALLED')
all_good = False
# 4. Check Django URLs
print()
print('4. Checking URL Routing...')
try:
from django.urls import reverse
# Check if routes exist (will raise NoReverseMatch if not found)
email_analysis_url = reverse('campaigns:email-analysis')
print(' ✓ Email analysis route registered')
except Exception as e:
print(f' ✗ URL routing issue: {e}')
all_good = False
# 5. Check API endpoints
print()
print('5. Checking API Endpoints...')
api_endpoints = [
('generate_email_with_ai', 'Email Generation'),
('analyze_campaign_topics', 'Topic Analysis'),
]
for func_name, description in api_endpoints:
try:
from campaigns import views
if hasattr(views, func_name):
print(f' ✓ {description:20} endpoint registered')
else:
print(f' ✗ {description:20} endpoint NOT found')
all_good = False
except Exception as e:
print(f' ✗ Error checking {description}: {e}')
all_good = False
# 6. Check file structure
print()
print('6. Checking File Structure...')
import os
files_to_check = [
('campaigns/ai_utils.py', 'AI Utilities Module'),
('templates/campaigns/email_analysis.html', 'Email Analysis Template'),
('campaigns/migrations/0006_emailaianalysis.py', 'Database Migration'),
]
for file_path, description in files_to_check:
full_path = os.path.join(os.path.dirname(__file__), file_path)
if os.path.exists(full_path):
print(f' ✓ {description:30} exists')
else:
print(f' ✗ {description:30} NOT found at {file_path}')
all_good = False
# 7. Summary
print()
print('=' * 70)
if all_good:
print(' ✅ ALL SYSTEMS OPERATIONAL')
print()
print('Your application is ready for:')
print(' • Email generation with AI (OpenAI)')
print(' • Topic analysis on campaigns (LDA)')
print()
print('Next Steps:')
print(' 1. Set OpenAI API key: set OPENAI_API_KEY=sk-...')
print(' 2. Navigate to /campaigns/email-analysis/')
print(' 3. Try AI features in email template editor')
else:
print(' ❌ SOME SYSTEMS NOT OPERATIONAL')
print()
print('Please review the errors above and:')
print(' 1. Reinstall dependencies: pip install -r requirements.txt')
print(' 2. Run migrations: python manage.py migrate')
print(' 3. Check Django setup: python manage.py check')
print('=' * 70)