Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Url Ai Transformer Laravel Package

spatie/laravel-url-ai-transformer

Laravel package to transform URLs and their web content with AI. Extract structured data (JSON-LD), generate summaries, images, or custom outputs via transformers and prompts. Runs via an Artisan command and stores results in the database for later retrieval.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel 12+ Native Integration: The package now requires Laravel 12+, aligning with the latest Laravel ecosystem (PHP 8.2+). This ensures compatibility with modern Laravel features like AI-first tooling (e.g., Laravel AI package) and improved performance optimizations.
  • Laravel AI Package Integration: Replaces Prism with the official Laravel AI package, reducing dependency complexity and leveraging Laravel’s native AI abstractions. This simplifies provider switching (e.g., OpenAI, Anthropic) and aligns with Laravel’s long-term AI strategy.
  • Modular Design Retained: Transformers remain pluggable, but now inherit from Laravel AI’s Concerns\InteractsWithAIModels, ensuring consistency with Laravel’s AI workflows.
  • Database-Centric: Still uses transformation_results, but future-proofed for Laravel 12’s Eloquent enhancements (e.g., model macros, query optimizations).

Integration Feasibility

  • Breaking Changes:
    • Prism Removal: Requires replacing Prism with the Laravel AI package (laravel/ai). This is a mandatory upgrade for existing users.
    • Laravel 12+ Requirement: Drops support for Laravel 10/11, necessitating a framework upgrade.
  • Simplified AI Setup:
    • Configuration now uses Laravel’s ai.php (e.g., AI_MODEL=gpt-4) instead of Prism-specific settings.
    • Example:
      // config/ai.php
      'models' => [
          'gpt-4' => [
              'provider' => 'openai',
              'model' => 'gpt-4',
          ],
      ],
      
  • Queue and Job Updates:
    • Jobs now extend Laravel\AI\Jobs\BaseJob, ensuring compatibility with Laravel’s AI queue optimizations.
    • Retry logic may need adjustments if using custom job middleware.
  • Customization Points:
    • Transformers: Extend Laravel\AI\Concerns\InteractsWithAIModels instead of Prism’s interfaces.
    • Prompts: Use Laravel AI’s Prompt class for dynamic prompt construction (e.g., Prompt::from('...')->toModel('gpt-4')).
    • Error Handling: Leverage Laravel AI’s exception handling (e.g., AIException).

Technical Risk

  • Laravel 12 Upgrade Risk:
    • Framework changes (e.g., Symfony 7.x, PHP 8.2+) may introduce compatibility issues with other packages.
    • Mitigation: Test thoroughly with a staging environment.
  • AI Provider Migration:
    • Prism-specific logic (e.g., custom providers) must be rewritten for Laravel AI.
    • Example: Replace Prism::make('openai')->complete() with AI::complete('gpt-4', '...').
  • Cost and Rate-Limiting:
    • Laravel AI’s abstractions may not expose all Prism features (e.g., fine-grained rate-limiting).
    • Workaround: Implement custom middleware or use provider-specific SDKs.
  • URL Fetching:
    • No changes, but ensure Laravel’s HTTP client (now using Symfony’s HttpClient) handles edge cases (e.g., redirects, auth).
  • Database Schema:
    • No schema changes, but Laravel 12’s Eloquent may require adjustments for queries (e.g., new query builder methods).
  • Performance:
    • Laravel AI’s caching layer may improve response times, but test with production-like loads.

Key Questions

  1. Laravel 12 Upgrade:
    • Are all dependencies compatible with Laravel 12 and PHP 8.2+?
    • What’s the timeline for upgrading from Laravel 11?
  2. AI Provider Strategy:
    • Which Laravel AI-supported providers will be used, and how will prompts be managed?
    • Are there custom AI features (e.g., fine-tuning) that require Prism?
  3. Migration Complexity:
    • How will Prism-specific logic (e.g., custom providers, retries) be ported to Laravel AI?
    • Example: Replace Prism::stream() with Laravel AI’s streaming API.
  4. Queue and Job Handling:
    • Will Laravel AI’s queue optimizations (e.g., batching) reduce costs?
    • Are custom job middleware or listeners needed for retries?
  5. Testing:
    • How will AI responses be validated (e.g., schema checks for LD+JSON) in the new setup?
    • Are there plans to test with Laravel’s AI testing utilities (e.g., AI::fake())?
  6. Cost Monitoring:
    • How will token usage be tracked with Laravel AI’s abstractions?
    • Are there plans to integrate with Laravel’s monitoring tools (e.g., Horizon)?
  7. Custom Transformers:
    • Will existing transformers need refactoring to use Laravel AI’s Prompt class?
    • Example:
      // Old (Prism)
      class LdJsonTransformer extends Transformer {
          public function transform(string $content): string {
              return Prism::make('openai')->complete('Extract LD+JSON from: ' . $content);
          }
      }
      // New (Laravel AI)
      class LdJsonTransformer extends Transformer {
          public function transform(string $content): string {
              return AI::complete('gpt-4', 'Extract LD+JSON from: ' . $content);
          }
      }
      

Integration Approach

Stack Fit

  • Laravel 12+: Mandatory for this release. Ensures compatibility with:
    • Laravel AI Package: Native integration for AI workflows.
    • Symfony 7.x: Improved HTTP client, process management, and performance.
    • PHP 8.2+: Features like read-only properties and native array functions.
  • Database: Continued support for MySQL, PostgreSQL, SQLite. No changes.
  • AI Providers: Now limited to providers supported by Laravel AI (e.g., OpenAI, Anthropic, Hugging Face). Custom providers require Laravel AI compatibility.
  • Queue System: Leverages Laravel’s improved queue optimizations (e.g., batching, retries).

Migration Path

  1. Upgrade Laravel:
  2. Install Laravel AI:
    composer require laravel/ai
    php artisan vendor:publish --provider="Laravel\AI\AIServiceProvider"
    
  3. Configure AI Providers:
    • Update .env with AI credentials (e.g., OPENAI_API_KEY).
    • Configure config/ai.php:
      'providers' => [
          'openai' => [
              'key' => env('OPENAI_API_KEY'),
              'secret' => env('OPENAI_API_SECRET'),
              'region' => env('OPENAI_REGION', 'us'),
          ],
      ],
      
  4. Update Package Configuration:
    • Publish the package config:
      php artisan vendor:publish --provider="Spatie\LaravelUrlAiTransformer\UrlAiTransformerServiceProvider"
      
    • Update config/url-ai-transformer.php to use Laravel AI models (e.g., model: 'gpt-4').
  5. Refactor Transformers:
    • Replace Prism calls with Laravel AI methods. Example:
      // Before
      use Prism\Prism;
      
      // After
      use Laravel\AI\Facades\AI;
      
    • Update prompts to use Prompt class:
      use Laravel\AI\Prompts\Prompt;
      
      public function transform(string $content): string {
          return AI::complete(
              Prompt::from('Extract LD+JSON from: ' . $content)->toModel('gpt-4')
          );
      }
      
  6. Test Migration:
    • Run a subset of URLs with --now flag to verify synchronous behavior.
    • Check transformation_results for errors or incomplete data.
  7. Update Jobs (Optional):
    • If custom jobs extend BaseJob, ensure they’re compatible with Laravel AI’s queue system.
    • Example retry logic:
      public function retryUntil(): ?DateTime
      {
          return now()->addMinutes(5); // Laravel AI's default retry
      }
      

Compatibility

  • Laravel Versions: Only Laravel 12+. No support for 10/11.
  • PHP Extensions: Requires PHP 8.2+ (e.g., ctype, fileinfo, curl).
  • AI Providers: Must be supported by Laravel AI. Unsupported providers require custom integration.
  • Queue Workers: Compatible with Laravel’s queue system (e.g., Redis, database). No changes.
  • Custom Code:
    • Prism-specific logic (e.g., Prism::stream()) must be replaced with Laravel AI equivalents.
    • Example: Use AI::stream() for streaming responses.

Sequencing

  1. **Phase
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony