A Laravel web application integrated with Ollama for AI-powered Q&A functionality. This application allows users to ask questions and receive intelligent responses generated by local language models.
- 🤖 AI Chat Interface - Ask questions and get responses from local language models
- 🔗 RESTful API - Clean API endpoints for AI interactions
- ⚡ Laravel Framework - Built with Laravel for robust web development
- 🏠 Local AI - Uses Ollama for running language models locally
- 📝 Request Validation - Proper input validation and error handling
Before running this application, make sure you have the following installed:
- PHP >= 8.1
- Composer - PHP dependency manager
- Laravel - Web framework
- Ollama - Local LLM service (for AI functionality)
- Node.js & npm (optional, for frontend assets)
-
Clone the repository:
git clone <repository-url> cd edu-ai
-
Install PHP dependencies:
composer install
-
Install Node.js dependencies (optional):
npm install
-
Set up environment:
cp .env.example .env php artisan key:generate
-
Install and start Ollama:
# Install Ollama (Linux) curl -fsSL https://ollama.ai/install.sh | sh # Pull a language model ollama pull phi3:mini # Start Ollama service sudo systemctl start ollama sudo systemctl enable ollama
-
Start the Laravel development server:
php artisan serve
The application provides a RESTful API for AI interactions:
Ask a question and receive an AI-generated response.
Request:
{
"question": "What is machine learning?"
}Response:
{
"question": "What is machine learning?",
"answer": "Machine learning is a subset of artificial intelligence that enables computers to learn and improve from experience without being explicitly programmed...",
"model": "phi3:mini"
}You can test the API using curl:
curl -X POST http://localhost:8000/api/ask-ai \
-H "Content-Type: application/json" \
-d '{"question": "What is crypto?"}'The application is configured to connect to Ollama running on localhost:11434. Make sure:
- Ollama service is running:
sudo systemctl status ollama - At least one model is available:
ollama list - The model specified in
AIController.phpexists
The application currently uses phi3:mini by default. You can change this in app/Http/Controllers/AIController.php:
'model' => 'phi3:mini', // Change to 'llama3' or other models├── app/
│ ├── Http/Controllers/
│ │ └── AIController.php # Main AI interaction logic
│ └── Models/ # Eloquent models
├── routes/
│ └── api.php # API route definitions
├── public/ # Public web assets
└── storage/ # Application storage
-
"Unable to connect to Ollama"
- Ensure Ollama service is running:
sudo systemctl start ollama - Check if port 11434 is accessible:
curl http://localhost:11434/api/tags
- Ensure Ollama service is running:
-
Slow responses
- The application uses a 180-second timeout for AI requests
- Consider using smaller models like
phi3:minifor better performance - Monitor system resources (CPU/Memory usage)
-
Model not found
- Pull the required model:
ollama pull phi3:mini - List available models:
ollama list
- Pull the required model:
- Laravel logs:
storage/logs/laravel.log - Ollama logs:
journalctl -u ollama --no-pager
php artisan testnpm run build
# or for development
npm run devThis project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if necessary
- Submit a pull request
Built with ❤️ using Laravel and Ollama