minhyung / error-solutions-gemini
Solution Provider using Gemini
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/minhyung/error-solutions-gemini
Requires
- google-gemini-php/client: ^2.7
- spatie/backtrace: ^1.6
- spatie/error-solutions: ^2.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.10
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
README
A spatie/error-solutions compatible Solution Provider powered by Google Gemini AI.
Requirements
- PHP 8.2+
- Composer
Installation
composer require minhyung/error-solutions-gemini
Basic Usage
use Minhyung\ErrorSolutionsGemini\Solutions\Gemini\GeminiSolutionProvider; use Spatie\ErrorSolutions\SolutionProviderRepository; $repository = new SolutionProviderRepository([ new GeminiSolutionProvider( apiKey: 'your-gemini-api-key', applicationType: 'PHP 8.3', applicationPath: __DIR__, ), ]); try { // Code that throws throw new \RuntimeException('Undefined variable $foo'); } catch (\Throwable $e) { $solutions = $repository->getSolutionsForThrowable($e); foreach ($solutions as $solution) { echo $solution->getSolutionTitle() . "\n"; echo $solution->getSolutionDescription() . "\n"; foreach ($solution->getDocumentationLinks() as $title => $url) { echo "- {$title}: {$url}\n"; } } }
Configuration
GeminiSolutionProvider constructor options
apiKey(required): Gemini API keycache(optional): PSR-16 cache implementationcacheTtlInSeconds(optional): Cache TTL, default 3600 secondsapplicationType(optional): Application type (e.g.,Laravel 11,Symfony 7)applicationPath(optional): Application root path for code snippet extractionmodel(optional): Gemini model, defaults toGemini\Enums\ModelType::GEMINI_FLASH
Cache usage example
use Psr\SimpleCache\CacheInterface; $provider = new GeminiSolutionProvider( apiKey: 'your-gemini-api-key', ); // Enable cache (optional) $provider->useCache($cache, cacheTtlInSeconds: 7200);
How It Works
- When an exception occurs, a prompt is built with file path, line number, code snippet, and the exception message.
- The prompt is sent to the Gemini API to request an AI-generated solution.
- The response is parsed to extract the fix (
FIX/ENDFIX) and related documentation links (LINKS/ENDLINKS). - When cache is enabled, repeat calls for the same exception are avoided.