Spaces:
Sleeping
Sleeping
File size: 9,089 Bytes
0b355ec | 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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | // MongoDB initialization script
// This script runs when the MongoDB container first starts
print('Initializing UGA Chatbot database...');
// Switch to the uga_chatbot database
db = db.getSiblingDB('uga_chatbot');
// Create collections with validation
db.createCollection('users', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['ugaId', 'email', 'firstName', 'lastName', 'role'],
properties: {
ugaId: { bsonType: 'string' },
email: { bsonType: 'string' },
firstName: { bsonType: 'string' },
lastName: { bsonType: 'string' },
role: { enum: ['student', 'faculty', 'admin'] },
classification: { bsonType: 'string' },
major: { bsonType: 'string' },
college: { bsonType: 'string' },
phone: { bsonType: 'string' },
address: { bsonType: 'string' },
preferences: { bsonType: 'object' },
lastLogin: { bsonType: 'date' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('conversations', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['userId', 'title', 'category'],
properties: {
userId: { bsonType: 'objectId' },
title: { bsonType: 'string' },
category: { bsonType: 'string' },
lastActivity: { bsonType: 'date' },
messageCount: { bsonType: 'int' },
archived: { bsonType: 'bool' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('messages', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['conversationId', 'role', 'content'],
properties: {
conversationId: { bsonType: 'objectId' },
role: { enum: ['user', 'assistant'] },
content: { bsonType: 'string' },
metadata: { bsonType: 'object' },
tokens: { bsonType: 'int' },
timestamp: { bsonType: 'date' },
createdAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('knowledgebase', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'content', 'category'],
properties: {
title: { bsonType: 'string' },
content: { bsonType: 'string' },
category: { bsonType: 'string' },
tags: { bsonType: 'array', items: { bsonType: 'string' } },
helpful: { bsonType: 'int' },
views: { bsonType: 'int' },
lastUpdated: { bsonType: 'date' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('agentactions', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['userId', 'action', 'status'],
properties: {
userId: { bsonType: 'objectId' },
conversationId: { bsonType: 'objectId' },
messageId: { bsonType: 'objectId' },
action: { bsonType: 'string' },
parameters: { bsonType: 'object' },
status: { enum: ['pending', 'in_progress', 'completed', 'failed'] },
result: { bsonType: 'object' },
error: { bsonType: 'string' },
executionTime: { bsonType: 'int' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
// Create indexes for performance
print('Creating database indexes...');
// Users collection indexes
db.users.createIndex({ ugaId: 1 }, { unique: true });
db.users.createIndex({ email: 1 }, { unique: true });
db.users.createIndex({ role: 1 });
db.users.createIndex({ createdAt: 1 });
// Conversations collection indexes
db.conversations.createIndex({ userId: 1 });
db.conversations.createIndex({ lastActivity: -1 });
db.conversations.createIndex({ category: 1 });
db.conversations.createIndex({ userId: 1, lastActivity: -1 });
// Messages collection indexes
db.messages.createIndex({ conversationId: 1 });
db.messages.createIndex({ timestamp: -1 });
db.messages.createIndex({ conversationId: 1, timestamp: 1 });
db.messages.createIndex({ role: 1 });
// Knowledge base collection indexes
db.knowledgebase.createIndex({ title: 'text', content: 'text', tags: 'text' });
db.knowledgebase.createIndex({ category: 1 });
db.knowledgebase.createIndex({ views: -1 });
db.knowledgebase.createIndex({ helpful: -1 });
db.knowledgebase.createIndex({ lastUpdated: -1 });
// Agent actions collection indexes
db.agentactions.createIndex({ userId: 1 });
db.agentactions.createIndex({ conversationId: 1 });
db.agentactions.createIndex({ status: 1 });
db.agentactions.createIndex({ action: 1 });
db.agentactions.createIndex({ createdAt: -1 });
// Create admin user if it doesn't exist
print('Creating admin user...');
const adminExists = db.users.findOne({ email: 'admin@uga.edu' });
if (!adminExists) {
db.users.insertOne({
ugaId: '000000000',
email: 'admin@uga.edu',
firstName: 'System',
lastName: 'Administrator',
role: 'admin',
preferences: {
notifications: {
email: true,
push: true,
sms: false
},
appearance: {
theme: 'light',
language: 'en'
}
},
createdAt: new Date(),
updatedAt: new Date()
});
print('Admin user created');
} else {
print('Admin user already exists');
}
// Seed knowledge base with essential UGA information
print('Seeding knowledge base...');
const essentialArticles = [
{
title: 'How to Register for Classes',
content: 'To register for classes at UGA, you need to use the Athena student information system. First, log in to Athena with your MyID credentials. Then navigate to Student Services > Registration. Check your registration time ticket to see when you can register. Search for classes by subject, course number, or instructor. Add classes to your cart and then enroll when your time ticket opens.',
category: 'academics',
tags: ['registration', 'athena', 'courses', 'enrollment'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'UGA MyID and ArchPass Authentication',
content: 'MyID is your universal UGA login that provides access to all university systems. ArchPass (powered by Duo) provides two-factor authentication for enhanced security. To set up ArchPass, go to archpass.uga.edu, log in with your MyID, and follow the instructions to register your device. You can use the Duo Mobile app, SMS, or phone calls for verification.',
category: 'technology',
tags: ['myid', 'archpass', 'duo', 'authentication', '2fa'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Financial Aid and HOPE Scholarship',
content: 'UGA offers various financial aid options including HOPE Scholarship, Pell Grants, and student loans. To apply for financial aid, complete the FAFSA form. HOPE Scholarship requires maintaining a 3.0 GPA for continued eligibility. Check your financial aid status in Athena under Financial Aid. For questions, contact the Financial Aid Office at 706-542-6147.',
category: 'financial',
tags: ['financial aid', 'hope', 'fafsa', 'scholarships', 'grants'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Campus Dining Locations and Hours',
content: 'UGA has numerous dining locations across campus. Major dining halls include ECV (East Campus Village), Oglethorpe House, Snelling, and Bolton. Most dining halls are open for breakfast, lunch, and dinner with extended hours during the week. Use your meal plan or Paw Points to pay. Check the UGA Dining website or mobile app for current hours and menus.',
category: 'campus-life',
tags: ['dining', 'food', 'meal-plan', 'hours', 'ecv'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Getting Help from EITS',
content: 'Enterprise Information Technology Services (EITS) provides IT support for students, faculty, and staff. Contact EITS by phone at 706-542-3106, email at helpdesk@uga.edu, or visit the Help Desk in the Miller Learning Center. EITS can help with MyID issues, software problems, network connectivity, and more. Online chat support is also available.',
category: 'technology',
tags: ['eits', 'help-desk', 'it-support', 'technical-help'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
}
];
// Insert articles if they don't exist
essentialArticles.forEach(article => {
const exists = db.knowledgebase.findOne({ title: article.title });
if (!exists) {
db.knowledgebase.insertOne(article);
print(`Inserted article: ${article.title}`);
}
});
print('Database initialization completed successfully!');
print('Collections created:', db.getCollectionNames().length);
print('Indexes created for optimal performance');
print('Essential knowledge base articles seeded'); |