adeel696/ai-wrapper
最新稳定版本:v1.0.0
Composer 安装命令:
composer require adeel696/ai-wrapper
包简介
A Laravel AI Wrapper
README 文档
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; });
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-22