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

0.1.0 2025-12-30 01:05 UTC

This package is auto-updated.

Last update: 2025-12-30 01:10:22 UTC


README

Tests

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 key
  • cache (optional): PSR-16 cache implementation
  • cacheTtlInSeconds (optional): Cache TTL, default 3600 seconds
  • applicationType (optional): Application type (e.g., Laravel 11, Symfony 7)
  • applicationPath (optional): Application root path for code snippet extraction
  • model (optional): Gemini model, defaults to Gemini\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

  1. When an exception occurs, a prompt is built with file path, line number, code snippet, and the exception message.
  2. The prompt is sent to the Gemini API to request an AI-generated solution.
  3. The response is parsed to extract the fix (FIX/ENDFIX) and related documentation links (LINKS/ENDLINKS).
  4. When cache is enabled, repeat calls for the same exception are avoided.