Installation &amp; setup | laravel-url-ai-transformer | Spatie

 SPATIE

  Laravel URL AI Transformer
=============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-url-ai-transformer](https://spatie.be/docs/laravel-url-ai-transformer/v1)  Installation &amp; setup

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-url-ai-transformer/v1)

  Installation &amp; setup
- [ Introduction ](https://spatie.be/docs/laravel-url-ai-transformer/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-url-ai-transformer/v1/support-us)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-url-ai-transformer/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-url-ai-transformer/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-url-ai-transformer/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-url-ai-transformer/v1/about-us)

Basic usage
-----------

- [ Getting started ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/getting-started)
- [ Registering transformations ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/registering-transformations)
- [ Writing your own transformers ](https://spatie.be/docs/laravel-url-ai-transformer/v1/basic-usage/writing-your-own-transformers)

Advanced usage
--------------

- [ Testing transformers ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/testing-transformers)
- [ Conditional transformations ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/conditional-transformations)
- [ Crawling URLs ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/crawling-urls)
- [ Customizing AI models ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/customizing-ai-models)
- [ Exploring command options ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/exploring-command-options)
- [ Overriding actions ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/overriding-actions)
- [ Regenerating results ](https://spatie.be/docs/laravel-url-ai-transformer/v1/advanced-usage/regenerating-results)

 Installation &amp; setup
========================

###  On this page

1. [ Publishing the config file ](#content-publishing-the-config-file)
2. [ Migrating the database ](#content-migrating-the-database)
3. [ Configuring AI providers ](#content-configuring-ai-providers)

You can install the package via composer:

```
composer require spatie/laravel-url-ai-transformer
```

Publishing the config file
--------------------------------------------------------------------------------------------------------------------------------------

Optionally, you can publish the config file with this command:

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

This is the content of the published config file:

```
return [
    /*
     * The model that will be used to store the transformation results.
     *
     * You can use your own model by extending the default model.
     */
    'model' => Spatie\LaravelUrlAiTransformer\Models\TransformationResult::class,

    /*
     * The actions that will perform low-level operations of the package.
     *
     * You can extend the default actions and specify your own actions here
     * to customize the package's behavior.
     */
    'actions' => [
        'fetch_url_content' => Spatie\LaravelUrlAiTransformer\Actions\FetchUrlContentAction::class,
        'process_registration' => Spatie\LaravelUrlAiTransformer\Actions\ProcessRegistrationAction::class,
    ],

    /*
     * The jobs that will handle background processing.
     *
     * You can extend the default jobs and specify your own jobs here
     * to customize the package's behavior.
     */

    'process_transformer_job' => Spatie\LaravelUrlAiTransformer\Jobs\ProcessTransformerJob::class,

    /*
     * By default, the transformers that ship with this package leverage the wonderful
     * Prism package to interact with various AI services.
     *
     * https://prismphp.com
     *
     * You can customize the default settings here.
     */
    'ai' => [
        'default' => [
            'provider' => Prism\Prism\Enums\Provider::OpenAI,
            'model' => 'gpt-4o-mini',
        ],

        'image' => [
            'provider' => Prism\Prism\Enums\Provider::OpenAI,
            'model' => 'dall-e-3',
        ],
    ],
];
```

Migrating the database
--------------------------------------------------------------------------------------------------------------------------

This package stored transformations results in the database. To create the `transformation_results` table, you must create and run the migration.

```
php artisan vendor:publish --tag="url-ai-transformer-migrations"
php artisan migrate
```

Configuring AI providers
--------------------------------------------------------------------------------------------------------------------------------

This package uses [Prism](https://prismphp.com) under the hood to interact with various AI services. Prism is a powerful, framework-agnostic PHP library that provides a unified interface for working with different AI providers.

By default, the package is configured to use OpenAI's GPT-4 models. To get started, you'll need to add your OpenAI API key to your `.env` file:

```
OPENAI_API_KEY=your-api-key-here
```

### Using different AI providers

Prism supports multiple AI providers including OpenAI, Anthropic Claude, Google Gemini, and more. You can easily switch providers by updating the config file:

```
'ai' => [
    'default' => [
        'provider' => Prism\Prism\Enums\Provider::Anthropic,
        'model' => 'claude-3-5-sonnet-20241022',
    ],
],
```

Don't forget to add the corresponding API key to your `.env` file:

```
# For Anthropic Claude
ANTHROPIC_API_KEY=your-api-key-here

# For Google Gemini
GEMINI_API_KEY=your-api-key-here
```

For more information about configuring Prism and the available providers, check out the [Prism documentation](https://prismphp.com/docs/providers).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
