Customizing AI models | 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)  Advanced-usage  Customizing AI models

 Version   v1

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

  Customizing AI models
- [ 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)

 Customizing AI models
=====================

###  On this page

1. [ Transformers without AI ](#content-transformers-without-ai)

By default, transformers use the AI provider and model configured in your `config/url-ai-transformer.php` file. However, you can customize which AI models to use on a per-transformer basis, or even skip AI entirely.

This package uses [Prism](https://prismphp.com) under the hood for all AI interactions. Prism provides a unified interface for working with different AI providers like OpenAI, Anthropic, Google Gemini, and more. For detailed information about available providers, models, and configuration options, check out the [Prism documentation](https://prismphp.com/docs).

Here's an example where we use various options like temperature and max tokens.

```
class PreciseTransformer extends Transformer
{
    public function transform(): void
    {
        $response = Prism::text()
            ->using(Config::aiProvider(), Config::aiModel())
            ->withPrompt($this->getPrompt())
            ->withMaxTokens(1000)
            ->withTemperature(0.1) // Low temperature for precise, consistent output
            ->asText();

        $this->transformationResult->result = $response->text;
    }
}

class CreativeTransformer extends Transformer
{
    public function transform(): void
    {
        $response = Prism::text()
            ->using(Config::aiProvider(), Config::aiModel())
            ->withPrompt($this->getPrompt())
            ->withMaxTokens(2000)
            ->withTemperature(0.8) // Higher temperature for creative output
            ->asText();

        $this->transformationResult->result = $response->text;
    }
}
```

Transformers without AI
-----------------------------------------------------------------------------------------------------------------------------

Not all transformers need to use AI. You can create transformers that process content using traditional methods:

```
class WordCountTransformer extends Transformer
{
    public function transform(): void
    {
        $wordCount = str_word_count(strip_tags($this->urlContent));

        $this->transformationResult->result =  $wordCount;
    }
}
```

 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)
