承接 saurabhshukla-developer/laravel-ai-chatbot 相关项目开发

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

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

saurabhshukla-developer/laravel-ai-chatbot

Composer 安装命令:

composer require saurabhshukla-developer/laravel-ai-chatbot

包简介

A comprehensive Laravel package for building AI agents with multiple provider support, tool management, and function calling capabilities

README 文档

README

Latest Version License PHP Version Laravel Version

A comprehensive Laravel package for building AI-powered chatbots and agents with support for multiple AI providers (OpenAI, Anthropic, Google AI). Features include encrypted API key management, AI agent creation with custom prompts, function calling tools, and a beautiful web interface for managing your AI infrastructure.

Repository: https://github.com/saurabhshukla-developer/laravel-ai-chatbot

✨ Features

  • 🔐 Secure API Key Management - Encrypted storage with support for multiple providers
  • 🤖 AI Agent Builder - Create custom AI agents with personalized prompts and configurations
  • 🛠️ Function Calling Tools - Powerful tool system for extending AI capabilities
    • File-based tools (auto-discovered PHP classes)
    • Database-backed tools (managed via web UI)
    • Easy tool creation with artisan commands
  • 🌐 Multi-Provider Support - OpenAI, Anthropic (Claude), and Google AI
  • 💬 Built-in Chat Interface - Ready-to-use web UI for testing agents
  • 🎨 Beautiful Web Dashboard - Manage keys, agents, and tools through an intuitive interface
  • 🔌 Programmatic API - Full code integration support for Laravel applications
  • 📡 Streaming Responses - Real-time response streaming for better UX
  • Fully Tested - Comprehensive test suite with 51 passing tests

Installation

For stable release (recommended):

composer require saurabhshukla-developer/laravel-ai-chatbot:^1.1.1

For development version:

composer config repositories.laravel-ai-chatbot vcs https://github.com/saurabhshukla-developer/laravel-ai-chatbot
composer require saurabhshukla-developer/laravel-ai-chatbot:dev-master

Publish configuration and migrations:

php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider" --tag="chatbot-config"
php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider" --tag="chatbot-migrations"
php artisan migrate

For detailed setup instructions, see docs/SETUP.md.

Updating to Latest Version

If you're already using this package and want to update to version 1.1.1:

composer update saurabhshukla-developer/laravel-ai-chatbot
php artisan migrate
php artisan cache:clear

What's New in 1.1.1:

  • Fixed tools folder-info route errors
  • Enhanced documentation organization
  • Comprehensive test coverage (51 tests, 100% passing)
  • Professional documentation formatting

New Feature: File-Based Tools - Create tools by simply adding PHP files! See docs/QUICK_START_TOOLS.md for a 3-step guide.

📦 Installation

Quick Install

composer require saurabhshukla-developer/laravel-ai-chatbot:dev-master
php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider"
php artisan migrate

Detailed Installation

Step 1: Install via Composer

Stable release (recommended):

composer require saurabhshukla-developer/laravel-ai-chatbot:^1.1.1

Development version:

# Add repository first
composer config repositories.laravel-ai-chatbot vcs https://github.com/saurabhshukla-developer/laravel-ai-chatbot

# Then require dev-master version
composer require saurabhshukla-developer/laravel-ai-chatbot:dev-master

Step 2: Publish Configuration and Migrations

php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider" --tag="chatbot-config"
php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider" --tag="chatbot-migrations"

Step 3: Run Migrations

php artisan migrate

Step 4: (Optional) Publish Views

If you want to customize the views:

php artisan vendor:publish --provider="LaravelAI\Chatbot\ChatbotServiceProvider" --tag="chatbot-views"

Configuration

After publishing the configuration file, you can customize it at config/chatbot.php:

return [
    'default_provider' => env('CHATBOT_DEFAULT_PROVIDER', 'openai'),
    
    'providers' => [
        'openai' => [
            'name' => 'OpenAI',
            'api_url' => env('OPENAI_API_URL', 'https://api.openai.com/v1'),
            'model' => env('OPENAI_MODEL', 'gpt-4'),
            // ...
        ],
        // ...
    ],
    
    'storage_driver' => env('CHATBOT_STORAGE_DRIVER', 'database'),
    
    'routes' => [
        'prefix' => env('CHATBOT_ROUTE_PREFIX', 'chatbot'),
        'middleware' => ['web'],
    ],
];

Usage

Managing API Keys

  1. Navigate to /chatbot/api-keys in your browser
  2. Click "Add API Key"
  3. Select your provider and enter your API key
  4. Optionally set it as the default for that provider

Creating AI Agents

  1. Navigate to /chatbot/agents in your browser
  2. Click "Create Agent"
  3. Fill in the agent details:
    • Name: A descriptive name for your agent
    • Provider: Choose OpenAI, Anthropic, or Google AI
    • Model: (Optional) Specific model to use
    • System Prompt: (Optional) Define the agent's behavior and personality
    • Tools: (Optional) Select tools that the agent can use
  4. Save the agent

Creating Tools

Method 1: File-Based Tools (Recommended - Easiest!)

Super Easy - Use Artisan Command:

php artisan chatbot:make-tool Calculator

That's it! Edit app/Tools/CalculatorTool.php and customize it.

Or create manually - Create PHP files in app/Tools/ directory:

<?php

namespace App\Tools;

use LaravelAI\Chatbot\Tools\BaseTool;

class CalculatorTool extends BaseTool
{
    public function name(): string
    {
        return 'Calculator';
    }

    public function description(): string
    {
        return 'Performs mathematical calculations';
    }

    public function parameters(): array
    {
        return [
            'properties' => [
                'expression' => [
                    'type' => 'string',
                    'description' => 'Mathematical expression (e.g., "2 + 2")',
                ],
            ],
            'required' => ['expression'],
        ];
    }

    public function execute(array $arguments): mixed
    {
        $expression = $arguments['expression'];
        $result = eval("return {$expression};");
        return ['result' => $result];
    }
}

That's it! The tool is automatically discovered and available for your agents. No database setup needed!

Available Commands:

  • php artisan chatbot:make-tool Name - Create a new tool
  • php artisan chatbot:test-tool slug - Test a tool
  • php artisan chatbot:list-tools - List all tools

See docs/EASY_TOOL_CREATION.md for details.

Method 2: Database Tools (Via Web UI)

  1. Navigate to /chatbot/tools in your browser
  2. Click "Create Tool"
  3. Fill in the tool details and save

For detailed examples, see:

Using Agents in Code

Basic Chat

use LaravelAI\Chatbot\Facades\Chatbot;

// Get an agent by slug or ID
$agent = Chatbot::getAgent('my-agent-slug');

// Chat with the agent
$response = Chatbot::chat($agent, 'Hello, how are you?');

echo $response['content'];

Using Specific Provider

use LaravelAI\Chatbot\Facades\Chatbot;

// Use a specific provider
$provider = Chatbot::provider('openai');

// Create an agent programmatically
$agent = Chatbot::createAgent([
    'name' => 'Customer Support Bot',
    'slug' => 'customer-support',
    'provider' => 'openai',
    'system_prompt' => 'You are a helpful customer support assistant.',
    'is_active' => true,
]);

// Chat with the agent
$response = Chatbot::chat($agent, 'I need help with my order');

Streaming Responses

use LaravelAI\Chatbot\Facades\Chatbot;

$agent = Chatbot::getAgent('my-agent');

foreach (Chatbot::streamChat($agent, 'Tell me a story') as $chunk) {
    if (!$chunk['done']) {
        echo $chunk['content'];
        flush();
    }
}

Advanced Options

$response = Chatbot::chat($agent, 'Your message', [
    'temperature' => 0.9,
    'max_tokens' => 1000,
    'model' => 'gpt-4-turbo', // Override agent's default model
]);

Using Agents with Tools

use LaravelAI\Chatbot\Facades\Chatbot;
use LaravelAI\Chatbot\Models\Tool;

// Get an agent
$agent = Chatbot::getAgent('math-assistant');

// Tools are automatically included when chatting
$response = Chatbot::chat($agent, 'What is 25 * 4?');

// The AI can use assigned tools to answer the question
echo $response['content'];

// To assign tools programmatically:
$calculatorTool = Tool::where('slug', 'calculator')->first();
$agent->tools()->attach($calculatorTool->id);

For more tool examples, see docs/TOOLS_EXAMPLES.md

📚 Documentation

Comprehensive documentation is available in the docs/ directory:

Getting Started

Tools & Development

Testing & Troubleshooting

See docs/README.md for the complete documentation index.

Direct Provider Access

use LaravelAI\Chatbot\Facades\Chatbot;

$provider = Chatbot::provider('openai');
$response = $provider->chat($agent, 'Hello');

Routes

The package automatically registers the following routes (with /chatbot prefix by default):

  • GET /chatbot/api-keys - List all API keys
  • GET /chatbot/api-keys/create - Create new API key form
  • POST /chatbot/api-keys - Store new API key
  • GET /chatbot/api-keys/{id}/edit - Edit API key form
  • PUT /chatbot/api-keys/{id} - Update API key
  • DELETE /chatbot/api-keys/{id} - Delete API key
  • GET /chatbot/agents - List all agents
  • GET /chatbot/agents/create - Create new agent form
  • POST /chatbot/agents - Store new agent
  • GET /chatbot/agents/{id} - View agent details and chat
  • GET /chatbot/agents/{id}/edit - Edit agent form
  • PUT /chatbot/agents/{id} - Update agent
  • DELETE /chatbot/agents/{id} - Delete agent
  • POST /chatbot/agents/{id}/chat - Chat with agent (API endpoint)
  • GET /chatbot/tools - List all tools
  • GET /chatbot/tools/create - Create new tool form
  • POST /chatbot/tools - Store new tool
  • GET /chatbot/tools/{id} - View tool details
  • GET /chatbot/tools/{id}/edit - Edit tool form
  • PUT /chatbot/tools/{id} - Update tool
  • DELETE /chatbot/tools/{id} - Delete tool

Environment Variables

You can set these in your .env file:

CHATBOT_DEFAULT_PROVIDER=openai
CHATBOT_STORAGE_DRIVER=database
CHATBOT_ROUTE_PREFIX=chatbot

# Provider-specific (optional if using database storage)
OPENAI_API_KEY=your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key
GOOGLE_AI_API_KEY=your-google-key

Security

  • API keys stored in the database are encrypted using Laravel's encryption
  • Make sure your APP_KEY is set in your .env file
  • API keys are never displayed in plain text in the UI
  • Consider adding authentication middleware to protect the routes

Supported Providers

OpenAI

Anthropic (Claude)

Google AI

Customization

Custom Provider

To add a custom provider, create a new provider class:

namespace App\Providers;

use LaravelAI\Chatbot\Providers\BaseProvider;
use LaravelAI\Chatbot\Models\AiAgent;

class CustomProvider extends BaseProvider
{
    protected function getProviderName(): string
    {
        return 'custom';
    }

    // Implement required methods...
}

Then register it in the ChatbotManager class.

Custom Views

Publish the views and customize them:

php artisan vendor:publish --tag="chatbot-views"

Views will be published to resources/views/vendor/chatbot/.

📋 Requirements

  • PHP: 8.1 or higher
  • Laravel: 10.x, 11.x, or 12.x
  • Dependencies: Guzzle HTTP Client (automatically installed)
  • Database: MySQL, PostgreSQL, or SQLite

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

🐛 Support & Issues

📝 Changelog

See CHANGELOG.md for a complete list of changes and version history.

👤 Author

Saurabh Shukla

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Made with ❤️ for the Laravel community

saurabhshukla-developer/laravel-ai-chatbot 适用场景与选型建议

saurabhshukla-developer/laravel-ai-chatbot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 9, 最近一次更新时间为 2025 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「tools」 「laravel」 「ai」 「chatbot」 「machine-learning」 「Gemini」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 saurabhshukla-developer/laravel-ai-chatbot 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 saurabhshukla-developer/laravel-ai-chatbot 我们能提供哪些服务?
定制开发 / 二次开发

基于 saurabhshukla-developer/laravel-ai-chatbot 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-21