Files
unai/AI_CHAT_SETUP.md
T
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

4.1 KiB

AI Chat Setup Guide

The University Portal includes an AI-powered chat assistant that can help users with information about the university, programs, admissions, and more. The AI chat is powered by Ollama, a local AI model runner.

Features

  • 🤖 AI-Powered Assistant: Get instant answers about university information
  • 💬 Real-time Chat: Interactive conversation interface
  • 🏠 Local Processing: Runs locally on your machine for privacy
  • 📱 Responsive Design: Works on desktop and mobile devices
  • 🎯 Context-Aware: Specialized for university-related questions

Quick Setup

1. Install Ollama

Run the automated setup script:

npm run setup:ollama

This script will:

  • Install Ollama on your system
  • Start the Ollama service
  • Download the Llama2 model

2. Manual Installation (Alternative)

If the automated script doesn't work, install Ollama manually:

macOS/Linux

curl -fsSL https://ollama.ai/install.sh | sh

Windows

Download from: https://ollama.ai/download

3. Start Ollama

ollama serve

4. Download a Model

ollama pull llama2

5. Start the Development Server

npm run dev

Using the AI Chat

  1. Access the Chat: Click the AI chat button in the bottom-right corner of any page
  2. Ask Questions: Type your questions about:
    • University programs and courses
    • Admission requirements
    • Campus life and facilities
    • Research opportunities
    • Student services
  3. Get Instant Answers: The AI will provide helpful, contextual responses

Available Models

The default model is llama2, but you can use any model supported by Ollama:

# List available models
ollama list

# Pull a different model
ollama pull codellama
ollama pull mistral
ollama pull llama2:13b

Configuration

Environment Variables

You can configure the Ollama connection in your .env.local file:

OLLAMA_HOST=http://localhost:11434

Model Selection

To use a different model, modify the API call in src/app/api/chat/ollama/route.ts:

body: JSON.stringify({
  message: userMessage.text,
  model: 'codellama' // Change this to your preferred model
}),

Troubleshooting

Ollama Not Running

If you see "Ollama is not running" in the chat:

  1. Check if Ollama is installed:

    ollama --version
    
  2. Start the Ollama service:

    ollama serve
    
  3. Verify it's running:

    curl http://localhost:11434/api/tags
    

Model Not Found

If you get a model error:

  1. List available models:

    ollama list
    
  2. Pull the required model:

    ollama pull llama2
    

Performance Issues

  • Slow Responses: Try a smaller model like llama2:7b
  • High Memory Usage: Close other applications or use a smaller model
  • Network Issues: Ensure Ollama is running locally

Commands Reference

# Start Ollama service
ollama serve

# Stop Ollama service
pkill ollama

# List models
ollama list

# Pull a model
ollama pull <model-name>

# Run a model interactively
ollama run llama2

# Remove a model
ollama rm <model-name>

Security & Privacy

  • Local Processing: All AI processing happens locally on your machine
  • No Data Collection: No user data is sent to external servers
  • Model Control: You control which models are installed and used

Support

If you encounter issues:

  1. Check the browser console for errors
  2. Verify Ollama is running: curl http://localhost:11434/api/tags
  3. Check the model is installed: ollama list
  4. Restart Ollama: pkill ollama && ollama serve

Advanced Usage

Custom System Prompts

You can customize the AI's behavior by modifying the system prompt in src/app/api/chat/ollama/route.ts:

const systemPrompt = `You are a helpful AI assistant for a university portal...`;

Multiple Models

You can implement model selection by adding a dropdown in the chat interface and passing the selected model to the API.

Streaming Responses

For real-time responses, you can implement streaming by modifying the API to use Ollama's streaming capabilities.