anastalal/filament-ai-rewriter

AI-powered content rewriter for FilamentPHP

Fund package maintenance!
anastalal

Installs: 19

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/anastalal/filament-ai-rewriter

v1.0.2 2026-02-06 14:54 UTC

This package is auto-updated.

Last update: 2026-02-06 14:58:57 UTC


README

Latest Version on Packagist Total Downloads License

AI-powered content rewriting for FilamentPHP. Enhance your forms with intelligent text refinement, creative expansion, and natural translations directly within your Filament fields.

Filament AI Rewriter

Features

  • Multi-Provider Support: Seamlessly switch between OpenAI (GPT-4/3.5), Google Gemini, and Anthropic Claude.
  • Unified Macro API: Add AI functionality to any text-based field using a simple ->withAi() macro.
  • Smart Input Filtering: Automatically hides AI actions on sensitive or strictly formatted fields (Password, Email, Numeric, etc.) to ensure data integrity.
  • Context-Aware Lengths: Intelligent response limits tailored to the field type (concise for TextInput, detailed for Textarea and Editors).
  • SEO Keywords: Naturally incorporate global or field-specific keywords into the rewritten content.
  • No Manual Bolding: Explicitly instructs AI to avoid unnecessary bolding or highlighting of keywords.
  • Smart Caching: Temperature-aware caching system with tag support for selective cache clearing.
  • Selective Cache Management: CLI utility to clear only AI-generated results from your cache.
  • Fully Multilingual: Native support for English and Arabic with extensible translation system.

Support

  • Filament: v3.x, v4.x, and v5.x

Installation

You can install the package via composer:

composer require anastalal/filament-ai-rewriter

Publish the configuration file:

php artisan vendor:publish --tag="filament-ai-rewriter-config"

Configuration

Add your API keys to your .env file:

AI_REWRITER_PROVIDER=openai
OPENAI_API_KEY=your-api-key-here

# Optional: Global SEO keywords
AI_REWRITER_GLOBAL_KEYWORDS="your, main, keywords"

The configuration file allows you to customize providers, models, default styles, and detailed AI prompts.

Usage

Simple Usage

Add AI rewrite capability to any TextInput, Textarea, RichEditor, or MarkdownEditor:

use Filament\Forms\Components\Textarea;

Textarea::make('description')
    ->withAi()

Advanced Usage

Customize the AI behavior for specific fields:

use Filament\Forms\Components\RichEditor;

RichEditor::make('content')
    ->withAi([
        'style' => 'creative',
        'keywords' => 'sale, unique, offer',
        'temperature' => 0.8,
        'max_tokens' => 2000,
    ])

Global Keywords

Keywords set in config/filament-ai-rewriter.php are automatically used in every request. Keywords provided via the withAi() macro will be merged with the global ones.

CLI Commands

Clear all AI-generated results from the cache:

php artisan filament-ai-rewriter:clear-cache

Note: Selective clearing requires a cache driver that supports tags (e.g., Redis or Memcached). Use --force to clear the entire application cache if your driver doesn't support tags:

php artisan filament-ai-rewriter:clear-cache --force

Testing

composer test

Credits

License

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