Skip to content

dehyabi/edu-ai

Repository files navigation

AI-Powered Laravel Application

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.

Features

  • 🤖 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

Prerequisites

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)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd edu-ai
  2. Install PHP dependencies:

    composer install
  3. Install Node.js dependencies (optional):

    npm install
  4. Set up environment:

    cp .env.example .env
    php artisan key:generate
  5. 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
  6. Start the Laravel development server:

    php artisan serve

Usage

API Endpoints

The application provides a RESTful API for AI interactions:

POST /api/ask-ai

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"
}

Testing the API

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?"}'

Configuration

Ollama Setup

The application is configured to connect to Ollama running on localhost:11434. Make sure:

  1. Ollama service is running: sudo systemctl status ollama
  2. At least one model is available: ollama list
  3. The model specified in AIController.php exists

Available Models

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

Project Structure

├── 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

Troubleshooting

Common Issues

  1. "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
  2. Slow responses

    • The application uses a 180-second timeout for AI requests
    • Consider using smaller models like phi3:mini for better performance
    • Monitor system resources (CPU/Memory usage)
  3. Model not found

    • Pull the required model: ollama pull phi3:mini
    • List available models: ollama list

Logs

  • Laravel logs: storage/logs/laravel.log
  • Ollama logs: journalctl -u ollama --no-pager

Development

Running Tests

php artisan test

Building Assets (if using frontend)

npm run build
# or for development
npm run dev

License

This project is licensed under the MIT License.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if necessary
  5. Submit a pull request

Built with ❤️ using Laravel and Ollama

About

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.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages