承接 mohammadsalamat/chat_ai 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mohammadsalamat/chat_ai

最新稳定版本:v1.6.5.1

Composer 安装命令:

composer require 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

README 文档

README

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

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

  • 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

  • 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

1. Install via Composer

Run the following command to install the package:

composer require mohammadsalamat/chat_ai

2. Publish Configuration (Optional)

php artisan vendor:publish

This command publishes the migration and view files.

3. Run Migrations

php artisan migrate

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

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

1. Use in a Controller or Route

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

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

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

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

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

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

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

License

This package is open-source and available under the MIT License.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-18