Files
unai/scripts/seed-knowledge-base.ts
Krikorios aa459f4bd6 🎉 Complete AI-Enhanced University Portal - Ready for Production
 Major Features Added:
- AI Chat with conversation memory and university-specific knowledge base
- Multi-tenant university support with white-label capabilities
- Professional admin interface for knowledge base management
- Advanced database schema with Prisma ORM
- Comprehensive documentation and guides
- Modern Next.js 15 + React 19 architecture
- Bilingual support (English/Arabic)
- Role-based access control
- Real-time chat interface with loading states

🔧 Technical Improvements:
- Fixed all linter errors and TypeScript issues
- Cleaned up codebase and removed legacy files
- Added comprehensive .gitignore
- Updated README with detailed setup instructions
- Optimized database schema and migrations
- Enhanced error handling and user experience

📚 Documentation:
- AI Conversation Memory Guide
- AI Enhancement Summary
- Developer Guide
- User Guide
- Complete setup and deployment instructions

🚀 Ready for GitHub deployment and production use!
2025-07-20 08:26:25 +04:00

236 lines
16 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const sampleKnowledgeBase = [
// Admissions Category
{
category: 'Admissions',
question: 'What are the admission requirements for international students?',
questionAr: 'ما هي متطلبات القبول للطلاب الدوليين؟',
answer: 'International students need: 1) High school diploma with minimum GPA 3.0, 2) English proficiency (IELTS 6.0+ or TOEFL 80+), 3) Valid passport, 4) Financial documentation showing ability to pay tuition, 5) Completed application form with all supporting documents. Contact admissions@university.edu for detailed requirements.',
answerAr: 'يحتاج الطلاب الدوليون إلى: 1) شهادة الثانوية العامة بمعدل تراكمي لا يقل عن 3.0، 2) إتقان اللغة الإنجليزية (IELTS 6.0+ أو TOEFL 80+)، 3) جواز سفر صالح، 4) وثائق مالية تثبت القدرة على دفع الرسوم الدراسية، 5) استمارة طلب مكتملة مع جميع المستندات الداعمة. اتصل بـ admissions@university.edu للحصول على المتطلبات التفصيلية.',
priority: 3,
isActive: true
},
{
category: 'Admissions',
question: 'When is the application deadline for the fall semester?',
questionAr: 'متى هو الموعد النهائي للتقديم للفصل الدراسي الخريفي؟',
answer: 'The application deadline for the fall semester is May 15th. Early decision applications are due by March 1st. We recommend submitting your application at least 2 weeks before the deadline to ensure all documents are processed on time.',
answerAr: 'الموعد النهائي للتقديم للفصل الدراسي الخريفي هو 15 مايو. طلبات القبول المبكر مستحقة في 1 مارس. نوصي بتقديم طلبك قبل أسبوعين على الأقل من الموعد النهائي لضمان معالجة جميع المستندات في الوقت المحدد.',
priority: 3,
isActive: true
},
{
category: 'Admissions',
question: 'How much is the application fee?',
questionAr: 'كم رسوم التقديم؟',
answer: 'The application fee is $50 USD for international students and $25 USD for domestic students. This fee is non-refundable and must be paid online when submitting your application.',
answerAr: 'رسوم التقديم 50 دولار أمريكي للطلاب الدوليين و 25 دولار أمريكي للطلاب المحليين. هذه الرسوم غير قابلة للاسترداد ويجب دفعها عبر الإنترنت عند تقديم طلبك.',
priority: 2,
isActive: true
},
// Programs Category
{
category: 'Programs',
question: 'What engineering programs do you offer?',
questionAr: 'ما هي برامج الهندسة التي تقدمونها؟',
answer: 'We offer: Computer Engineering, Mechanical Engineering, Electrical Engineering, Civil Engineering, Chemical Engineering, and Biomedical Engineering. All programs are ABET-accredited and include hands-on laboratory work, industry internships, and capstone projects.',
answerAr: 'نقدم: هندسة الحاسوب، الهندسة الميكانيكية، الهندسة الكهربائية، الهندسة المدنية، الهندسة الكيميائية، وهندسة الطب الحيوي. جميع البرامج معتمدة من ABET وتشمل العمل المخبري العملي، التدريب الصناعي، ومشاريع التخرج.',
priority: 2,
isActive: true
},
{
category: 'Programs',
question: 'What is the duration of undergraduate programs?',
questionAr: 'ما هي مدة برامج البكالوريوس؟',
answer: 'Most undergraduate programs are 4 years (8 semesters) with 120-130 credit hours required for graduation. Some programs may take longer if you choose to study part-time or need to complete prerequisite courses.',
answerAr: 'معظم برامج البكالوريوس مدتها 4 سنوات (8 فصول دراسية) مع 120-130 ساعة معتمدة مطلوبة للتخرج. قد تستغرق بعض البرامج وقتًا أطول إذا اخترت الدراسة بدوام جزئي أو تحتاج إلى إكمال دورات متطلبات مسبقة.',
priority: 2,
isActive: true
},
{
category: 'Programs',
question: 'Do you offer online programs?',
questionAr: 'هل تقدمون برامج عبر الإنترنت؟',
answer: 'Yes, we offer several online programs including: Master of Business Administration (MBA), Master of Computer Science, and various certificate programs. Online students have access to the same resources and support as on-campus students.',
answerAr: 'نعم، نقدم عدة برامج عبر الإنترنت تشمل: ماجستير إدارة الأعمال (MBA)، ماجستير علوم الحاسوب، وبرامج شهادات متنوعة. الطلاب عبر الإنترنت لديهم إمكانية الوصول إلى نفس الموارد والدعم مثل الطلاب في الحرم الجامعي.',
priority: 2,
isActive: true
},
// Campus Life Category
{
category: 'Campus Life',
question: 'What housing options are available for students?',
questionAr: 'ما خيارات السكن المتاحة للطلاب؟',
answer: 'We offer on-campus dormitories, apartment-style housing, and off-campus housing assistance. On-campus housing includes meal plans and is guaranteed for first-year students. Off-campus housing options include university-affiliated apartments and private rentals.',
answerAr: 'نقدم مساكن داخل الحرم الجامعي، سكن على طراز الشقق، ومساعدة السكن خارج الحرم الجامعي. السكن داخل الحرم الجامعي يشمل خطط الوجبات ومضمون لطلاب السنة الأولى. خيارات السكن خارج الحرم الجامعي تشمل شقق مرتبطة بالجامعة وإيجارات خاصة.',
priority: 2,
isActive: true
},
{
category: 'Campus Life',
question: 'What sports and recreation facilities are available?',
questionAr: 'ما المرافق الرياضية والترفيهية المتاحة؟',
answer: 'Our campus features: Olympic-size swimming pool, fitness center with modern equipment, tennis courts, basketball courts, soccer field, running track, and indoor sports complex. We also offer intramural sports, fitness classes, and outdoor adventure programs.',
answerAr: 'يتميز حرمنا الجامعي بـ: مسبح بحجم أولمبي، مركز لياقة بدنية بمعدات حديثة، ملاعب تنس، ملاعب كرة سلة، ملعب كرة قدم، مضمار جري، ومجمع رياضي داخلي. نقدم أيضًا رياضات داخلية، دروس لياقة بدنية، وبرامج مغامرات في الهواء الطلق.',
priority: 1,
isActive: true
},
{
category: 'Campus Life',
question: 'What student clubs and organizations are available?',
questionAr: 'ما النوادي والمنظمات الطلابية المتاحة؟',
answer: 'We have over 100 student organizations including: academic clubs, cultural organizations, professional societies, volunteer groups, and special interest clubs. Students can also start new organizations with faculty sponsorship.',
answerAr: 'لدينا أكثر من 100 منظمة طلابية تشمل: نوادي أكاديمية، منظمات ثقافية، جمعيات مهنية، مجموعات تطوعية، ونوادي اهتمامات خاصة. يمكن للطلاب أيضًا إنشاء منظمات جديدة برعاية أعضاء هيئة التدريس.',
priority: 1,
isActive: true
},
// Financial Aid Category
{
category: 'Financial Aid',
question: 'What scholarships are available for international students?',
questionAr: 'ما المنح الدراسية المتاحة للطلاب الدوليين؟',
answer: 'We offer: Merit-based scholarships (up to $10,000/year), Academic Excellence scholarships, Leadership scholarships, and Country-specific scholarships. All international students are automatically considered for merit-based scholarships.',
answerAr: 'نقدم: منح دراسية على أساس الجدارة (حتى 10,000 دولار/سنة)، منح التميز الأكاديمي، منح القيادة، ومنح خاصة بالدول. جميع الطلاب الدوليين مؤهلون تلقائيًا للمنح الدراسية على أساس الجدارة.',
priority: 3,
isActive: true
},
{
category: 'Financial Aid',
question: 'How much is the tuition for international students?',
questionAr: 'كم الرسوم الدراسية للطلاب الدوليين؟',
answer: 'Tuition for international students is $25,000 USD per academic year. This includes: tuition, health insurance, and student services fees. Additional costs include: housing ($8,000-12,000/year), meals ($3,000-5,000/year), and personal expenses.',
answerAr: 'الرسوم الدراسية للطلاب الدوليين 25,000 دولار أمريكي لكل عام دراسي. هذا يشمل: الرسوم الدراسية، التأمين الصحي، ورسوم الخدمات الطلابية. التكاليف الإضافية تشمل: السكن (8,000-12,000 دولار/سنة)، الوجبات (3,000-5,000 دولار/سنة)، والمصروفات الشخصية.',
priority: 3,
isActive: true
},
{
category: 'Financial Aid',
question: 'Can international students work on campus?',
questionAr: 'هل يمكن للطلاب الدوليين العمل في الحرم الجامعي؟',
answer: 'Yes, international students can work up to 20 hours per week on campus during the academic year and full-time during breaks. Popular on-campus jobs include: library assistant, research assistant, dining services, and administrative support.',
answerAr: 'نعم، يمكن للطلاب الدوليين العمل حتى 20 ساعة في الأسبوع في الحرم الجامعي خلال العام الدراسي وبدوام كامل خلال العطلات. الوظائف الشائعة في الحرم الجامعي تشمل: مساعد مكتبة، مساعد بحث، خدمات الطعام، والدعم الإداري.',
priority: 2,
isActive: true
},
// Research Category
{
category: 'Research',
question: 'What research opportunities are available for undergraduate students?',
questionAr: 'ما فرص البحث المتاحة لطلاب البكالوريوس؟',
answer: 'Undergraduate students can participate in: faculty-led research projects, summer research programs, independent study projects, and research internships. We also offer research grants and travel funding for students presenting at conferences.',
answerAr: 'يمكن لطلاب البكالوريوس المشاركة في: مشاريع بحثية بقيادة أعضاء هيئة التدريس، برامج البحث الصيفية، مشاريع الدراسة المستقلة، وتدريبات البحث. نقدم أيضًا منح بحثية وتمويل سفر للطلاب الذين يقدمون في المؤتمرات.',
priority: 2,
isActive: true
},
{
category: 'Research',
question: 'What are the main research areas at the university?',
questionAr: 'ما مجالات البحث الرئيسية في الجامعة؟',
answer: 'Our main research areas include: Artificial Intelligence and Machine Learning, Renewable Energy, Biomedical Engineering, Environmental Science, Cybersecurity, and Sustainable Development. We have state-of-the-art research facilities and collaborate with industry partners.',
answerAr: 'تشمل مجالات البحث الرئيسية لدينا: الذكاء الاصطناعي والتعلم الآلي، الطاقة المتجددة، هندسة الطب الحيوي، العلوم البيئية، الأمن السيبراني، والتنمية المستدامة. لدينا مرافق بحثية متطورة ونتعاون مع شركاء الصناعة.',
priority: 2,
isActive: true
}
];
async function seedKnowledgeBase() {
try {
console.log('🌱 Starting knowledge base seeding...');
// Get the first university (or create one if none exists)
let university = await prisma.university.findFirst();
if (!university) {
console.log('No university found, creating a default university...');
university = await prisma.university.create({
data: {
slug: 'default-university',
name: 'Default University',
shortName: 'DU',
domain: 'default-university.localhost',
subdomain: 'default',
branding: {
primaryColor: '#2563eb',
secondaryColor: '#1e40af',
logo: '/images/logo.png',
favicon: '/favicon.ico',
theme: 'modern'
},
contact: {
email: 'info@default-university.edu',
phone: '+1-555-0123',
address: '123 University Ave, Default City, DC 12345',
website: 'https://default-university.edu'
},
features: {
chatbot: true,
multiLanguage: true,
onlineApplications: true,
studentPortal: true,
courseManagement: true,
contentManagement: true
},
ai: {
provider: 'openrouter',
model: 'anthropic/claude-3.5-sonnet',
apiKey: '',
knowledgeBase: true,
chatHistory: true,
languageSupport: ['en', 'ar']
},
status: 'ACTIVE'
}
});
console.log('✅ Default university created');
}
// Clear existing knowledge base items for this university
await prisma.aIKnowledgeBase.deleteMany({
where: { universityId: university.id }
});
console.log('🗑️ Cleared existing knowledge base items');
// Create new knowledge base items
const createdItems = await Promise.all(
sampleKnowledgeBase.map(item =>
prisma.aIKnowledgeBase.create({
data: {
...item,
universityId: university.id
}
})
)
);
console.log(`✅ Successfully created ${createdItems.length} knowledge base items`);
// Display summary
const categories = [...new Set(sampleKnowledgeBase.map(item => item.category))];
console.log('\n📊 Knowledge Base Summary:');
console.log(`- Total Items: ${createdItems.length}`);
console.log(`- Categories: ${categories.join(', ')}`);
console.log(`- Bilingual Items: ${sampleKnowledgeBase.filter(item => item.questionAr && item.answerAr).length}`);
console.log(`- High Priority Items: ${sampleKnowledgeBase.filter(item => item.priority === 3).length}`);
console.log('\n🎉 Knowledge base seeding completed successfully!');
console.log('\n📝 Next Steps:');
console.log('1. Start the development server: npm run dev');
console.log('2. Navigate to /admin/knowledge-base to manage the knowledge base');
console.log('3. Test the AI chat with conversation memory');
console.log('4. Customize the knowledge base for your specific university');
} catch (error) {
console.error('❌ Error seeding knowledge base:', error);
} finally {
await prisma.$disconnect();
}
}
seedKnowledgeBase();