adeel696/ai-wrapper

A Laravel AI Wrapper

v1.0.0 2025-05-22 11:31 UTC

This package is auto-updated.

Last update: 2025-05-28 10:32:47 UTC


README

adeel696/ai-wrapper is a Laravel package that provides a unified interface to interact with multiple AI providers such as OpenAI (ChatGPT), Anthropic Claude, and Google Gemini โ€” all from a simple, Laravel-friendly wrapper.

๐Ÿš€ Features

  • ๐Ÿ”Œ Unified interface for multiple AI providers
  • ๐Ÿง  Support for OpenAI, Claude (Anthropic), and Gemini (Google)
  • ๐Ÿ“ฆ Works out of the box with Laravel's config and service provider system
  • ๐Ÿ” Runtime switching of providers and models (setProvider(), setModel())
  • ๐Ÿงฐ Wrapper methods like chat, summarize, translate, embed, and more
  • ๐Ÿงช Easy to extend with additional providers

๐Ÿ“ฆ Installation

composer require adeel696/ai-wrapper

โš™๏ธ Configuration & ๐Ÿงช Usage

php artisan vendor:publish --tag=config

Update config/ai.php as needed:

return [

    'default_provider' => 'openai',
    'default_model' => 'gpt-3.5-turbo',

    'providers' => [
        'openai' => ['api_key' => env('OPENAI_API_KEY')],
        'anthropic' => ['api_key' => env('ANTHROPIC_API_KEY')],
        'google' => ['api_key' => env('GOOGLE_AI_API_KEY')],
    ],

    'models' => [
        'openai' => ['default' => 'gpt-3.5-turbo'],
        'claude' => ['default' => 'claude-3-opus-20240229'],
        'gemini' => ['default' => 'gemini-pro'],
    ],
];

In your .env file, add the relevant API keys:

OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
GOOGLE_AI_API_KEY=your-google-api-key

Import and Initialize

use adeel696\AiWrapper\AiManager;

$ai = new AiManager();

Usage Examples

๐Ÿ” Set Provider and Model (Optional)

$ai->setProvider('claude')->setModel('claude-3-opus-20240229');

๐Ÿ’ฌ Chat (Default Provider)

$response = $ai->chat("Tell me about Laravel.");
echo $response;

๐Ÿ“„ Summarize Text

$text = "Laravel is a PHP framework designed for web artisans...";
echo $ai->summarize($text);

๐ŸŒ Translate Text

echo $ai->translate("How are you?", "es");

๐Ÿง  Embed Text (for semantic search)

$vector = $ai->embed("What is AI?");
print_r($vector);

๐ŸŽง Transcribe Audio

$response = $ai->transcribeAudio(storage_path('audio/voice.mp3'));
echo $response;

๐Ÿงฉ Stream Output (if supported by provider)

$ai->stream("Tell me a joke.", function ($chunk) {
    echo $chunk;
});