PHPackages                             mohammadsalamat/chat\_ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mohammadsalamat/chat\_ai

ActiveLibrary[API Development](/categories/api)

mohammadsalamat/chat\_ai
========================

The Chat AI Laravel Package is a smart chatbot integration for Laravel applications. It dynamically retrieves responses from multiple sources, prioritizing efficiency and accuracy

v1.6.5.1(1y ago)017MITPHPPHP &gt;=8.0

Since Feb 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/abokaesr1/chat_ai)[ Packagist](https://packagist.org/packages/mohammadsalamat/chat_ai)[ RSS](/packages/mohammadsalamat-chat-ai/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (14)Used By (0)

**Chat AI Laravel Package**
===========================

[](#chat-ai-laravel-package)

**Overview**
------------

[](#overview)

The **Chat AI Laravel Package** is an intelligent chatbot integration for Laravel applications. It retrieves responses dynamically from multiple sources, ensuring accuracy and efficiency:

1. **Database** – Checks for an existing response.
2. **ChatGPT** – If no response is found in the database, it queries OpenAI’s ChatGPT.
3. **Gemini AI** – If ChatGPT reaches its limit, it switches to Google Gemini.
4. **Google Search** – If no AI-generated response is available, it fetches relevant search results.
5. **Self-Learning** – If an answer is not found, it is stored in the database for future queries.

### How It Works

[](#how-it-works)

The chatbot follows a structured search approach:

1. **Database Lookup**

    - The chatbot first searches the database for a response.
    - Admins can manually add a list of questions and answers.
    - If the user's question is at least **70% similar** (adjustable via the config file) to a stored question, it retrieves the answer.
2. **ChatGPT Integration**

    - If no answer is found in the database, it queries ChatGPT.
    - The response is then stored in the database to reduce API usage and allow admin modifications.
3. **Fallback to Gemini AI**

    - If ChatGPT is inactive or has reached its limit, the chatbot switches to **Gemini AI** and follows the same process.
4. **Google Search**

    - If neither ChatGPT nor Gemini AI provides an answer, it fetches relevant data using Google Search.

### Provides

[](#provides)

- **Simple Blade View** – A minimal and customizable chat interface.
- **Lightweight Controller** – A clean structure to handle requests and responses.
- **Database Migration** – Stores previous queries and responses for improved efficiency.

**Features**
------------

[](#features)

- **Multi-source response system** (Database → ChatGPT → Gemini → Google Search).
- **Self-learning AI** – Stores new questions and answers.
- **Efficient fallback mechanism** for uninterrupted responses.
- **Simple API interface** for easy integration.
- **Optimized for performance** with caching and similarity checks.

**Installation**
----------------

[](#installation)

### **1. Install via Composer**

[](#1-install-via-composer)

Run the following command to install the package:

```
composer require mohammadsalamat/chat_ai
```

### **2. Publish Configuration (Optional)**

[](#2-publish-configuration-optional)

```
php artisan vendor:publish
```

This command publishes the migration and view files.

### **3. Run Migrations**

[](#3-run-migrations)

```
php artisan migrate
```

This creates a new database table called `questions` to store chatbot interactions.

### **4. Add API Keys to `.env`**

[](#4-add-api-keys-to-env)

Obtain API keys for OpenAI, Gemini, and Google Search, then update your `.env` file:

```
CHATGPT_API_KEY=your_chatgpt_api_key
GEMINI_API_KEY=your_gemini_api_key
GOOGLE_SEARCH_API_KEY=your_google_search_api_key
GOOGLE_SEARCH_CX=your_google_search_cx
```

**Usage**
---------

[](#usage)

### **1. Use in a Controller or Route**

[](#1-use-in-a-controller-or-route)

#### **Dependency Injection Approach**

[](#dependency-injection-approach)

```
use Salamat\chat_ai\Http\Controllers\ChatAiController;

public function sendMessage(Request $request, ChatAiController $controller)
{
    return $controller->generateText($request);
}
```

#### **Instantiating the Controller Manually**

[](#instantiating-the-controller-manually)

```
use Salamat\chat_ai\Http\Controllers\ChatAiController;

public function sendMessage(Request $request)
{
    $controller = new ChatAiController();
    return $controller->generateText($request);
}
```

### **2. Create a POST Route to Send a Message**

[](#2-create-a-post-route-to-send-a-message)

```
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Route;

Route::post('/sendMessage', [Controller::class, 'sendMessage']);
```

### **3. Frontend Integration**

[](#3-frontend-integration)

Send an AJAX request to your Laravel endpoint. A custom view is available at `resources/views/chat_ai`, including the following AJAX request:

```
fetch('/sendMessage', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-CSRF-TOKEN': '{{ csrf_token() }}' // CSRF token for security
    },
    body: JSON.stringify({
        message: messageText
    })
})
.then(response => response.json())
.then(data => console.log(data));
```

**Configuration**
-----------------

[](#configuration)

The package includes a configuration file located at `config/chat_ai.php`, where you can customize settings such as:

- **API Limits**
- **Similarity Threshold**
- **Caching Options**

**Contributing**
----------------

[](#contributing)

Feel free to submit pull requests or open issues for bug fixes and feature requests.

**License**
-----------

[](#license)

This package is open-source and available under the [MIT License](LICENSE).

---

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance43

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

13

Last Release

448d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/95d9ad9f12272e3e1906ebe2a2577e5ec8746187dcabda2574c2c32afcb1fd6e?d=identicon)[abokaesr1](/maintainers/abokaesr1)

---

Top Contributors

[![abokaesr1](https://avatars.githubusercontent.com/u/51765940?v=4)](https://github.com/abokaesr1 "abokaesr1 (22 commits)")

### Embed Badge

![Health badge](/badges/mohammadsalamat-chat-ai/health.svg)

```
[![Health](https://phpackages.com/badges/mohammadsalamat-chat-ai/health.svg)](https://phpackages.com/packages/mohammadsalamat-chat-ai)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
