PHPackages                             hamzad/laravel-ai-summary - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hamzad/laravel-ai-summary

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hamzad/laravel-ai-summary
=========================

A reusable Laravel package for AI-powered content summarization supporting OpenAI, Anthropic, Gemini, Mistral, Groq, and OpenRouter.

00PHP

Since May 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/tmolavi/laravel-ai-summary)[ Packagist](https://packagist.org/packages/hamzad/laravel-ai-summary)[ RSS](/packages/hamzad-laravel-ai-summary/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel AI Summary
==================

[](#laravel-ai-summary)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9a997871a675711e43c342a9225f6c4ea6cb33057b0eb45dc96a66793e04c09c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d7a61642f6c61726176656c2d61692d73756d6d6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hamzad/laravel-ai-summary)[![Tests](https://camo.githubusercontent.com/5dca22a9afa1d09822189fc0c1f8ad4cea5ee4d70312d180b5bd4dcbad45b7d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f68616d7a61642f6c61726176656c2d61692d73756d6d6172792f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/hamzad/laravel-ai-summary/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/f4244628ffb1a0747ee4764c2a1f88a41b352121a3fbc91e715a50cb4e493708/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d7a61642f6c61726176656c2d61692d73756d6d6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hamzad/laravel-ai-summary)[![PHP Version](https://camo.githubusercontent.com/fca6a5abe8cb8ca5a09d7514f79421a5acfc883e66c5e71627c5051291b2c4ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c75653f7374796c653d666c61742d737175617265)](#)[![Laravel Version](https://camo.githubusercontent.com/4598b92348d94043e852bead9bf32239a4511ee4d46d69e3055605428db2b7a1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3130253242253230253743253230313125324225323025374325323031322532422d7265643f7374796c653d666c61742d737175617265)](#)[![License](https://camo.githubusercontent.com/9f96a0581d164f656a87530c9ccaa2cc8d418944bfcc2966bfb102cfe420ad9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616d7a61642f6c61726176656c2d61692d73756d6d6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hamzad/laravel-ai-summary)

A beautiful, provider-agnostic Laravel package for AI-powered content summarization. Extract high-quality summaries, SEO titles, meta descriptions, and semantic entities from any text using your favorite LLM.

Why this package?
-----------------

[](#why-this-package)

Most AI packages tie you directly to OpenAI, forcing you to rewrite your codebase when you want to switch to cheaper/faster alternatives like Groq or Gemini.

**Laravel AI Summary** acts as an abstraction layer:

- **Provider-Agnostic**: Switch between OpenAI, Claude, Gemini, Mistral, Groq, or OpenRouter instantly.
- **Auto-Fallbacks**: If OpenAI is down or rate-limited, the package will automatically retry the prompt with Gemini or Claude.
- **Cache-Ready**: Saves API costs by automatically caching identical summaries.
- **Zero Heavy Dependencies**: Uses Laravel's native HTTP client. No bloated SDKs.
- **Perfect for**: Newsrooms, Blogs, CMS platforms, SaaS apps, and internal knowledge bases.

Warning

This package provides the architecture and API client logic. It **does not** provide free AI generation. You must obtain and provide your own API keys from the respective providers.

---

🏗 Architecture Diagram
----------------------

[](#-architecture-diagram)

 ```
graph TD
    A[AiSummary Facade] --> B[AiSummaryManager]
    B -->|Checks Cache| C{Cache Hit?}
    C -->|Yes| D[Return Cached SummaryResponse]
    C -->|No| E[Determine Provider Chain]
    E --> F[Primary Provider e.g. OpenAI]
    F -->|Success| G[Return & Cache SummaryResponse]
    F -->|Rate Limit / Timeout| H[Fallback Provider e.g. Gemini]
    H -->|Success| G
    H -->|Fail| I[Throw SummaryGenerationException]
```

      Loading 📊 Provider Comparison
---------------------

[](#-provider-comparison)

ProviderSpeedIntelligenceBest ForNative JSON Mode**Groq**⚡️ Extremely FastHigh (Llama 3)Real-time generationYes**OpenAI**🚀 FastVery High (GPT-4o)Complex SEO extractionYes**Anthropic**🚀 FastHighest (Claude 3.5)Nuanced analysisPrompt-based**Gemini**🚀 FastHigh (Gemini 1.5)High-context windowsYes---

🚀 Installation
--------------

[](#-installation)

Install the package via composer:

```
composer require hamzad/laravel-ai-summary
```

You can optionally publish the config file:

```
php artisan vendor:publish --tag="ai-summary-config"
```

⚙️ Configuration
----------------

[](#️-configuration)

Configure your `.env` with the default driver and keys:

```
AI_SUMMARY_DRIVER=openai
AI_SUMMARY_LANGUAGE=en

# API Keys
OPENAI_API_KEY="sk-..."
ANTHROPIC_API_KEY="sk-ant-..."
GEMINI_API_KEY="AIza..."
MISTRAL_API_KEY="mistral-..."
GROQ_API_KEY="gsk_..."
OPENROUTER_API_KEY="sk-or-..."
```

---

💡 Usage Examples
----------------

[](#-usage-examples)

### 1. Basic Controller Usage

[](#1-basic-controller-usage)

```
use Hamzad\AiSummary\Facades\AiSummary;

class ArticleController extends Controller
{
    public function show(Article $article)
    {
        $response = AiSummary::text($article->body)
            ->language('fa') // Generate Persian summary
            ->length('short') // 'short', 'medium', 'long'
            ->driver('gemini') // Override the default provider
            ->generate();

        return view('article.show', [
            'article' => $article,
            'aiSummary' => $response->summary,
            'aiSeoTitle' => $response->seoTitle,
        ]);
    }
}
```

### 2. Eloquent Model Usage

[](#2-eloquent-model-usage)

You can pass an Eloquent model directly. It will extract the `content` or `body` attribute automatically.

```
$summary = AiSummary::for($article)->generate();
```

### 3. Background Jobs (Recommended)

[](#3-background-jobs-recommended)

Since LLMs take 2-10 seconds to respond, you should dispatch summarization to the queue.

```
class GenerateSummaryJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public Article $article) {}

    public function handle()
    {
        $response = AiSummary::for($this->article)->generate();

        $this->article->update([
            'summary' => $response->summary,
            'seo_title' => $response->seoTitle,
        ]);
    }
}
```

### 4. Livewire Component

[](#4-livewire-component)

```
use Livewire\Component;
use Hamzad\AiSummary\Facades\AiSummary;

class AiAssistant extends Component
{
    public string $content = '';
    public string $summary = '';

    public function generateSummary()
    {
        $this->summary = AiSummary::text($this->content)
            ->driver('groq') // Use Groq for instant UI feedback
            ->withoutCache()
            ->generate()
            ->summary;
    }
}
```

---

🛡 Fallback Providers
--------------------

[](#-fallback-providers)

In `config/ai-summary.php`, define a chain of fallbacks. If your primary driver hits a rate limit (429) or a 500 error, the package automatically retries using the next provider!

```
'default' => 'openai',
'fallbacks' => [
    'gemini',
    'anthropic'
],
```

📦 Caching
---------

[](#-caching)

Caching is enabled by default (TTL: 24h) to save API costs. The cache key is generated using an MD5 hash of the content, language, length, and provider.

```
// Disable cache for this specific request
AiSummary::text($content)->withoutCache()->generate();

// Set custom TTL (in seconds)
AiSummary::text($content)->cache(ttl: 3600)->generate();
```

🛠 Extending (Custom Providers)
------------------------------

[](#-extending-custom-providers)

You can easily register a custom provider (e.g. local LLM or custom endpoint) in your `AppServiceProvider`:

```
use Hamzad\AiSummary\Facades\AiSummary;
use App\Services\LocalLlamaProvider;

public function boot()
{
    AiSummary::extend('llama', function ($app) {
        return new LocalLlamaProvider(config('services.llama'));
    });
}
```

Then use it seamlessly:

```
AiSummary::text('Hello')->driver('llama')->generate();
```

🩺 Troubleshooting
-----------------

[](#-troubleshooting)

**Error: `ProviderNotConfiguredException: API Key is missing`**

- You selected a driver in your `.env` but forgot to provide the matching `_API_KEY`.

**Error: `SummaryGenerationException: All AI providers in the fallback chain failed`**

- Check your network connectivity to the provider. If using Iranian servers, you may need to configure proxy settings inside Laravel's HTTP client or route via a proxy endpoint.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance59

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86704654?v=4)[Taqi Molavi | Taghi Molavi](/maintainers/tmolavi)[@tmolavi](https://github.com/tmolavi)

---

Tags

aiclaudegeminigroqlaravelmistralopenaiopenrouterseo-automation-llmsummarizationsummary

### Embed Badge

![Health badge](/badges/hamzad-laravel-ai-summary/health.svg)

```
[![Health](https://phpackages.com/badges/hamzad-laravel-ai-summary/health.svg)](https://phpackages.com/packages/hamzad-laravel-ai-summary)
```

###  Alternatives

[typo3/cms-composer-installers

TYPO3 CMS Installers

6114.7M69](/packages/typo3-cms-composer-installers)[yarovikov/gutengood

Base for yours blocks

131.8k](/packages/yarovikov-gutengood)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
