Download the PHP package aitoolkit/laravel-ai-toolkit without Composer
On this page you can find all versions of the php package aitoolkit/laravel-ai-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aitoolkit/laravel-ai-toolkit
More information about aitoolkit/laravel-ai-toolkit
Files in aitoolkit/laravel-ai-toolkit
Package laravel-ai-toolkit
Short Description A professional, production-ready Laravel package for integrating multiple AI providers with advanced features like asyncprocessing, real-time streaming, intelligent caching, and error handling.
License
Informations about the package laravel-ai-toolkit
Laravel AI Toolkit
A professional, production-ready Laravel package for integrating multiple AI providers with advanced features like async processing, real-time streaming, intelligent caching, and error handling.
โจ Features
๐ค Multi-Provider AI Support
- OpenAI - GPT-4, GPT-3.5, and embeddings
- Anthropic - Claude 4 Sonnet, Claude 3 Opus, and more
- Groq - Ultra-fast inference with Mixtral and Llama models
- Easy provider switching via configuration
โก Performance & Reliability
- Async Queue Jobs - Non-blocking AI operations
- Intelligent Caching - Redis/Database cache with TTL and invalidation
- Circuit Breaker Pattern - Automatic failure protection
- Exponential Backoff - Smart retry logic with jitter
- Rate Limiting - Built-in API rate limit handling
๐ Real-Time Features
- Streaming Responses - Real-time AI response streaming
- Laravel Reverb Integration - WebSocket broadcasting for live updates
- Event-Driven Architecture - Dispatch events for UI updates
๐ง Developer Experience
- Type-Safe Contracts - Interface-driven provider architecture
- Comprehensive CLI - Command-line tools for testing and management
- Laravel Facades - Easy dependency injection
- Rich Configuration - Environment-based provider settings
- Extensible Design - Easy to add new providers
๐ฆ Installation
Requirements
- PHP 8.3 or higher
- Laravel 11 or 12
- Composer
Install via Composer
Publish Configuration
This creates config/ai-toolkit.php where you can configure your providers.
Environment Variables
Add your API keys to .env:
๐ Quick Start
Basic Usage
Using Facades
Async Jobs
Streaming Responses
CLI Usage
โ๏ธ Configuration
Provider Settings
Cache Settings
Queue Settings
Broadcasting Settings
๐๏ธ Architecture
Provider Pattern
All AI providers implement AIProviderContract:
Service Architecture
Caching Strategy
Retry Logic
๐งช Testing
Run the test suite:
Run with coverage:
The package includes:
- Unit Tests - Individual component testing
- Feature Tests - Integration testing
- Provider Tests - Mock API testing
- Service Tests - Caching, retry logic, and jobs
๐ API Reference
AIProviderContract
chat(string $prompt, array $options = []): array
Send a chat message to the AI provider.
Parameters:
$prompt- The user message$options- Additional parameters (model, max_tokens, temperature, etc.)
Returns:
stream(string $prompt, array $options = []): StreamedResponse
Stream a chat response in real-time.
embed(string $text): array
Generate text embeddings (OpenAI only).
AiCacheService
remember(string $operation, string $provider, string $input, callable $callback, array $options = []): mixed
Cache AI responses with automatic TTL.
generateKey(string $operation, string $provider, string $input, array $options = []): string
Generate consistent cache keys.
invalidatePattern(string $pattern): int
Invalidate cache by pattern.
RetryService
execute(callable $callback, array $options = []): mixed
Execute operations with retry logic.
Options:
max_retries- Maximum retry attempts (default: 3)base_delay- Base delay in seconds (default: 1)strategy- 'exponential', 'linear', or 'fixed'circuit_breaker- Enable circuit breaker (default: true)
๐ Security
- API Key Validation - Validates provider keys on initialization
- Input Sanitization - All inputs are sanitized before API calls
- Rate Limiting - Built-in rate limit handling
- Error Handling - No sensitive data in error messages
- Caching - Cached responses don't include API keys
๐ Performance Tips
1. Enable Caching
2. Use Async Jobs for Long Operations
3. Monitor Cache Hit Rates
4. Use Circuit Breakers
๐ Advanced Usage
Custom Providers
Create a custom provider by implementing the contract:
Register in your service provider:
Event Listeners
Custom Caching
๐ Troubleshooting
Common Issues
1. "Invalid AI provider" Error
- Check your
ai.default_providerconfiguration - Ensure the provider name matches exactly: 'openai', 'anthropic', or 'groq'
2. API Key Not Found
- Verify environment variables are set
- Check for typos in variable names
- Ensure the config file is published
3. Streaming Not Working
- Enable broadcasting in config
- Set up Laravel Reverb or Pusher
- Check browser console for WebSocket errors
4. Queue Jobs Not Running
- Ensure queue driver is configured
- Run
php artisan queue:work - Check Laravel logs for errors
Debug Mode
Enable detailed logging:
๐ค Contributing
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
Development Setup
๐ License
This package is open-sourced software licensed under the MIT license.
๐ Support
- ๐ Issues: GitHub Issues
๐ Acknowledgments
- OpenAI for their excellent APIs
- Anthropic for Claude
- Groq for lightning-fast inference
- Laravel for the amazing framework
๐๏ธ Filament Admin Panel Integration
The Laravel AI Toolkit includes optional Filament Admin Panel integration for a beautiful web interface to manage AI providers, monitor usage, and test AI operations.
Quick Setup
Features
- โ AI Provider Management - Configure multiple providers (OpenAI, Anthropic, Groq)
- โ Real-time Chat Dashboard - Interactive AI testing interface
- โ Usage Analytics - Monitor requests, cache hit rates, response times
- โ Provider Testing - Built-in connection testing for all providers
- โ Encrypted Storage - API keys encrypted in database
- โ Dynamic Configuration - Database-driven provider management
Database-Driven Architecture
The Filament integration uses a database-first approach:
- Providers stored in database (not config files)
- Encrypted API keys for security
- Dynamic configuration via admin UI
- Seeder creates initial providers from
.envvalues
Documentation
๐ Full documentation available in: docs/FILAMENT_INTEGRATION.md
Includes detailed setup, configuration, troubleshooting, and advanced usage examples.
Made with โค๏ธ for the Laravel community
All versions of laravel-ai-toolkit with dependencies
laravel/framework Version ^11.0|^12.0
openai-php/client Version v0.17.0
anthropic-ai/sdk Version v0.3.0
filament/filament Version ^4.0