diff --git a/app/Http/Controllers/AIAnalysisController.php b/app/Http/Controllers/AIAnalysisController.php index 7ea4d58..c198331 100644 --- a/app/Http/Controllers/AIAnalysisController.php +++ b/app/Http/Controllers/AIAnalysisController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Candidate; use App\Services\AIAnalysisService; use Illuminate\Http\Request; +use Carbon\Carbon; class AIAnalysisController extends Controller { @@ -21,6 +22,16 @@ class AIAnalysisController extends Controller abort(403); } + // Restriction: Une analyse tous les 7 jours maximum par candidat + if ($candidate->ai_analysis && isset($candidate->ai_analysis['analyzed_at'])) { + $lastAnalysis = Carbon::parse($candidate->ai_analysis['analyzed_at']); + if ($lastAnalysis->diffInDays(now()) < 7) { + return response()->json([ + 'error' => "Une analyse a déjà été effectuée il y a moins de 7 jours. Merci de patienter avant de relancer l'IA." + ], 422); + } + } + try { $analysis = $this->aiService->analyze($candidate, $request->provider); diff --git a/app/Services/AIAnalysisService.php b/app/Services/AIAnalysisService.php index f17590c..682ead0 100644 --- a/app/Services/AIAnalysisService.php +++ b/app/Services/AIAnalysisService.php @@ -115,8 +115,9 @@ class AIAnalysisService default => $this->callOllama($prompt), }; - // Inject provider name for display + // Inject metadata for display and tracking $analysis['provider'] = $provider; + $analysis['analyzed_at'] = now()->toIso8601String(); return $analysis; } diff --git a/resources/js/Pages/Admin/Candidates/Show.vue b/resources/js/Pages/Admin/Candidates/Show.vue index aeff72e..11fa428 100644 --- a/resources/js/Pages/Admin/Candidates/Show.vue +++ b/resources/js/Pages/Admin/Candidates/Show.vue @@ -365,14 +365,19 @@ const runAI = async () => {
-

+

Analyse IA complète - - {{ aiAnalysis.provider }} - +
+ + {{ aiAnalysis.provider }} + + + Effectuée le {{ new Date(aiAnalysis.analyzed_at).toLocaleDateString('fr-FR') }} + +

Choisir l'IA pour l'analyse du matching

diff --git a/test-gemini.php b/test-gemini.php deleted file mode 100644 index 09a32d4..0000000 --- a/test-gemini.php +++ /dev/null @@ -1,27 +0,0 @@ -make(Illuminate\Contracts\Console\Kernel::class); -$kernel->bootstrap(); - -use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Log; - -$apiKey = env('GEMINI_API_KEY'); -if (!$apiKey) { - echo "API Key not found in .env\n"; - exit; -} - -echo "Testing Gemini models with key: " . substr($apiKey, 0, 5) . "...\n"; - -$response = Http::get("https://generativelanguage.googleapis.com/v1/models?key=" . $apiKey); - -if ($response->successful()) { - $models = $response->json('models'); - foreach ($models as $model) { - echo "- " . $model['name'] . " (" . implode(", ", $model['supportedGenerationMethods']) . ")\n"; - } -} else { - echo "Failed to list models: " . $response->status() . " - " . $response->body() . "\n"; -}