Using AI powered solutions
Ignition can send your exception to OpenAI that will attempt to automatically suggest a solution. In many cases, the suggested solutions is quite useful, but keep in mind that the solution may not be 100% correct for your context.
Configuration in a Laravel app
To generate AI powered solutions, you must first install this optional dependency.
composer require openai-php/client
We use cache to minimize calls made to OpenAI when your API generates many similar errors.
Configuration in a non-Laravel app
To generate AI powered solutions, you must first install this optional dependency.
composer require openai-php/client
To start sending your errors to OpenAI, you must instanciate the OpenAiSolutionProvider
. The constructor expects a OpenAI API key to be passed, you should generate this key at OpenAI.
use \Spatie\Ignition\Solutions\OpenAi\OpenAiSolutionProvider;
$aiSolutionProvider = new OpenAiSolutionProvider($openAiKey);
To use the solution provider, you should pass it to addSolutionProviders
when registering Ignition.
\Spatie\Ignition\Ignition::make()
->addSolutionProviders([
$aiSolutionProvider,
// other solution providers...
])
->register();
By default, the solution provider will send these bits of info to OpenAI:
- the error message
- the error class
- the stack frame
- other small bits of info of context surrounding your error
It will not send the request payload or any environment variables to avoid sending sensitive data to OpenAI.
Caching requests to AI
By default, all errors will be sent to OpenAI. Optionally, you can add caching so similar errors will only get sent to OpenAI once. To cache errors, you can call useCache
on $aiSolutionProvider
. You should pass a simple-cache-implementation. Here's the signature of the useCache
method.
public function useCache(CacheInterface $cache, int $cacheTtlInSeconds = 60 * 60)
Hinting the application type
To increase the quality of the suggested solutions, you can send along the application type (Symfony, Drupal, WordPress, ...) to the AI.
To send the application type call applicationType
on the solution provider.
$aiSolutionProvider->applicationType('WordPress 6.2');