darvis/laravel-ai-generator
Composer 安装命令:
composer require darvis/laravel-ai-generator
包简介
AI content generation service for Laravel applications with OpenAI support
README 文档
README
AI-powered content generation service for Laravel applications. Generate blog posts, articles, news items, and more with SEO optimization and optional image generation.
Features
- 🤖 OpenAI Integration - Uses GPT models for high-quality content
- 📝 Structured Output - Title, intro, text, SEO title, SEO description
- 🖼️ Image Generation - Optional AI-generated hero images
- 🌍 Multi-language - Support for Dutch, English, German, French, and more
- 🎯 SEO Optimized - Automatic SEO title and meta description
- ⚙️ Configurable - Tone, reading level, max words, and more
- 🔌 Driver-based - Easy to extend with new AI providers
Requirements
- PHP 8.2+
- Laravel 11.0+ or 12.0+
- OpenAI API key
Installation
composer require darvis/laravel-ai-generator
Publish the configuration file:
php artisan vendor:publish --tag=ai-generator-config
Add your OpenAI API key to .env:
OPENAI_API_KEY=your-api-key-here
Quick Start
use Darvis\LaravelAiGenerator\AiGenerator; use Darvis\LaravelAiGenerator\ContentRequest; $generator = app(AiGenerator::class); $result = $generator->generate(new ContentRequest( topic: 'The benefits of Laravel for web development', language: 'en', )); // Access the generated content echo $result->title; // "Why Laravel is the Best PHP Framework" echo $result->intro; // "Laravel has revolutionized..." echo $result->text; // "<h2>Introduction</h2><p>..." echo $result->seoTitle; // "Laravel Benefits | Web Development" echo $result->seoDescription; // "Discover why Laravel..."
Usage
Basic Usage
use Darvis\LaravelAiGenerator\AiGenerator; use Darvis\LaravelAiGenerator\ContentRequest; $generator = app(AiGenerator::class); $result = $generator->generate(new ContentRequest( topic: 'Your topic here', ));
Full Options
$result = $generator->generate(new ContentRequest( topic: 'Sustainable packaging solutions', language: 'nl', // nl|en|de|fr... audience: 'business owners', // Target audience tone: 'formal', // informal|neutral|formal readingLevel: 'expert', // general|expert|simple keywords: ['eco-friendly', 'packaging', 'sustainable'], cta: 'Request a quote', // Call to action brand: 'EcoPack BV', // Brand name maxWords: 600, // Max words for main text includeImage: true, // Generate image prompt imageStyle: 'photo', // photo|illustration|flat|3d imageAspect: '16:9', // 1:1|4:5|16:9 ));
Using the Facade
use Darvis\LaravelAiGenerator\Facades\AiGenerator; $result = AiGenerator::generate(new ContentRequest( topic: 'Your topic here', ));
ContentResult Properties
$result->title; // Generated title $result->intro; // 2-4 sentence introduction (plain text) $result->text; // Main content with HTML formatting $result->seoTitle; // SEO title (max 60 chars) $result->seoDescription; // Meta description (max 155 chars) $result->imagePrompt; // English prompt for image generation $result->imageUrl; // Generated image URL (if available) $result->imageBase64; // Generated image as base64 (if available) $result->errorMessage; // Error message (if any) // Helper methods $result->hasError(); // Check if there was an error $result->hasImage(); // Check if image was generated
Configuration
// config/ai-generator.php return [ 'driver' => env('AI_GENERATOR_DRIVER', 'openai'), 'default_language' => env('AI_GENERATOR_LANGUAGE', 'nl'), 'defaults' => [ 'tone' => env('AI_GENERATOR_TONE', 'informal'), 'reading_level' => env('AI_GENERATOR_LEVEL', 'general'), 'max_words' => env('AI_GENERATOR_MAX_WORDS', 900), ], 'drivers' => [ 'openai' => [ 'api_key' => env('OPENAI_API_KEY'), 'base_url' => env('OPENAI_BASE_URL', 'https://api.openai.com/v1'), 'model' => env('OPENAI_MODEL', 'gpt-4.1-mini'), 'image_model' => env('OPENAI_IMAGE_MODEL', 'gpt-image-1'), 'temperature' => env('OPENAI_TEMPERATURE', 0.7), 'timeout' => env('OPENAI_TIMEOUT', 45), ], ], ];
Environment Variables
| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
- | Your OpenAI API key (required) |
OPENAI_BASE_URL |
https://api.openai.com/v1 |
OpenAI API base URL |
OPENAI_MODEL |
gpt-4.1-mini |
Model for text generation |
OPENAI_IMAGE_MODEL |
gpt-image-1 |
Model for image generation |
OPENAI_TEMPERATURE |
0.7 |
Creativity level (0-1) |
OPENAI_TIMEOUT |
45 |
Request timeout in seconds |
AI_GENERATOR_LANGUAGE |
nl |
Default content language |
AI_GENERATOR_TONE |
informal |
Default tone of voice |
AI_GENERATOR_LEVEL |
general |
Default reading level |
AI_GENERATOR_MAX_WORDS |
900 |
Default max words |
Creating Custom Drivers
Implement the AiContentDriver interface:
use Darvis\LaravelAiGenerator\Contracts\AiContentDriver; use Darvis\LaravelAiGenerator\ContentRequest; use Darvis\LaravelAiGenerator\ContentResult; class AnthropicDriver implements AiContentDriver { public function generate(ContentRequest $request): ContentResult { // Your implementation here } }
Register in the service provider or config.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email info@arvid.nl instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
darvis/laravel-ai-generator 适用场景与选型建议
darvis/laravel-ai-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 darvis/laravel-ai-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darvis/laravel-ai-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-27