Skip to content

luckmoshi/codeigniter-neuron-ai-chat

 
 

Repository files navigation

CodeIgniter Neuron AI Chat

A demonstration project showcasing AI-powered chat functionality in CodeIgniter 4 using the Neuron AI library and Ollama for local LLM integration. This project features conversational agents with memory, persistent conversation history, and automatic summarization capabilities.

Screen

Requirements

This project requires Ollama and CodeIgniter 4.8-dev or later.

Installing CodeIgniter 4.8-dev

If CodeIgniter 4.8 hasn't been released yet, you'll need to switch to the development version after installation. Start by updating your project to the development build:

php builds development

Then edit your composer.json file to require the dev version:

"require": {
    "codeigniter4/codeigniter4": "4.8.x-dev"
}

Finally, update your dependencies:

composer update

Installation

Place the project files in your app/ThirdParty/neuronchat directory.

Configure Autoloading

Edit app/Config/Autoload.php and add the namespace to the $psr4 array:

<?php

namespace Config;

use CodeIgniter\Config\AutoloadConfig;

class Autoload extends AutoloadConfig
{
    public $psr4 = [
        APP_NAMESPACE => APPPATH,
        'Michalsn\CodeIgniterNeuronChat' => APPPATH . 'ThirdParty/neuronchat/src',
    ];

    // ...
}

Database Setup

Configure your site URL and database credentials in the .env file:

app.baseURL = 'http://ci48.test'

database.default.hostname = 127.0.0.1
database.default.database = your_database
database.default.username = your_username
database.default.password = your_password
database.default.DBDriver = MySQLi # or other driver

Run migrations to create the required database tables:

php spark migrate --all

Install Ollama Model

Download and start the qwen3:1.7b model that this project uses:

ollama run qwen3:1.7b

This will download the model if it's not already installed and start the Ollama service.

Usage

Once installation is complete, access the chat interface at your site URL followed by /chat. For example, if your base URL is http://ci48.test, navigate to http://ci48.test/chat.

Customization

The project includes two main agent classes that you can customize to change behavior or use different models:

  • MyAgent (src/Neuron/MyAgent.php) - Handles the main chat interactions
  • SummaryAgent (src/Neuron/SummaryAgent.php) - Generates conversation summaries

You can modify these classes to change system prompts, adjust parameters, or switch to different Ollama models. You can even use a different provider - see the list on Neuron docs.

Learn More

For a brief walkthrough of this project's implementation and architecture, check out the accompanying blog post.

About

A demo project showcasing AI-powered chat functionality in CodeIgniter 4 framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%