echolabsdev/prism
Prism is a Laravel package that simplifies integrating LLMs into your app. Use a fluent API to generate text, manage multi-step conversations, and run tools across multiple AI providers—so you can build AI features without provider-specific complexity.
Strengths:
macroable support), enabling seamless integration with existing Laravel patterns (e.g., commands, queues, or Livewire).thinkingLevel), and custom tool definitions allow tailored configurations for niche use cases.ToolResultEvent, CompletionEvent) and callbacks (e.g., onComplete) enable logging, monitoring, or real-time UI updates (e.g., streaming responses).Gaps:
max_tokens).use Prism\Prism;
Prism::make('openai')
->complete('Generate a blog post about Laravel 11')
->onComplete(fn ($response) => Log::info($response->content));
Prism::make()->stream()->toQueue('llm-jobs')).guzzlehttp/guzzle (for HTTP calls) and symfony/http-client (optional). No major conflicts with Laravel’s default stack.openai-php) are optional if using Prism’s direct HTTP layer.structuredOutput().onComplete handlers (e.g., removal of onComplete in favor of CompletionEvent) may need refactoring.thought_signature, thinkingLevel) differs from OpenAI; edge cases may arise in multi-provider setups.streamEnd events) require careful event listener setup.max_execution_time.PrismProviderOverloadedException)? Example:
Prism::make()->catch(fn (Exception $e) => notify($e->getMessage()));
PrismJob::failed()).Prism::fake(), but integration tests may need provider API keys.Prism::make('openai')). Extend via:
$this->app->bind('prism.openai', fn () => new CustomOpenAIProvider());
ToolResultEvent) or create custom ones for domain-specific logic.Artisan::call('prism:complete', [
'provider' => 'anthropic',
'prompt' => 'Summarize this document',
'--tools' => json_encode([...]),
]);
- **Queues**: Offload heavy operations (e.g., embeddings, multi-turn chats) to queues:
```php
Prism::make()->stream()->toQueue('llm-queue');
public function mount() {
Prism::make()->stream()->onChunk(fn ($chunk) => $this->emit('llm-chunk', $chunk));
}
Prism::fake() to mock responses in tests:
Prism::fake([
'openai.completions' => fn () => 'Mocked response',
]);
OpenAI::complete() for Prism::make('openai')->complete()).config('prism.default_provider')).'providers' => [
'openai' => [
'key' => env('OPENAI_KEY'),
'model' => 'gpt-4',
],
'anthropic' => [
'key' => env('ANTHROPIC_KEY'),
'model' => 'claude-3',
],
],
composer require prism-php/prism
php artisan vendor:publish --provider="Prism\PrismServiceProvider"
.env and config/prism.php.Prism::make('openai')->chat()).// Before
$response = OpenAI::chat()->create([...]);
// After
$response = Prism::make('openai')->chat()->create([...]);
Prism::make()->tool('summarize')->onResult(fn ($result) => $this->storeSummary($result));
How can I help you explore Laravel packages today?