From 8cd46398c0dc8350219be5718822a238ee3e04ea Mon Sep 17 00:00:00 2001 From: boban Date: Sun, 17 May 2026 14:44:18 +0200 Subject: [PATCH] fix(ai): language-aware prompt, better insights, larger spinner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Prompt respects user locale (de/en/fr/es/it/pt) — responds in user's language - Rewrite prompt: domain pattern analysis, low-click diagnosis, no generic advice - Include total clicks + link count for context - max_tokens 512 → 800 for richer output - Button spinner: h-5 w-5 (was h-4 w-4), bg-inherit to cover label text cleanly Co-Authored-By: Claude Sonnet 4.6 --- app/Domains/Ai/Services/AiService.php | 2 +- app/Livewire/Pages/Ai/Insights.php | 26 +++++++++++++++++-- .../views/components/ui/button.blade.php | 4 +-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Domains/Ai/Services/AiService.php b/app/Domains/Ai/Services/AiService.php index 4939272..bb8c3ec 100644 --- a/app/Domains/Ai/Services/AiService.php +++ b/app/Domains/Ai/Services/AiService.php @@ -19,7 +19,7 @@ class AiService 'Content-Type' => 'application/json', ])->post('https://api.openai.com/v1/chat/completions', [ 'model' => $model, - 'max_tokens' => 512, + 'max_tokens' => 800, 'messages' => [['role' => 'user', 'content' => $prompt]], ]); diff --git a/app/Livewire/Pages/Ai/Insights.php b/app/Livewire/Pages/Ai/Insights.php index 39a87b6..4e8d7fd 100644 --- a/app/Livewire/Pages/Ai/Insights.php +++ b/app/Livewire/Pages/Ai/Insights.php @@ -45,9 +45,31 @@ class Insights extends Component return; } - $summary = $topLinks->map(fn ($l) => "{$l->slug}: {$l->clicks_count} clicks → {$l->target_url}")->implode("\n"); + $locale = auth()->user()?->locale ?? 'en'; + $langMap = ['de' => 'German', 'en' => 'English', 'fr' => 'French', 'es' => 'Spanish', 'it' => 'Italian', 'pt' => 'Portuguese']; + $language = $langMap[$locale] ?? 'English'; - $prompt = "You are a marketing analyst. Analyze these link performance stats and provide 3-5 actionable insights:\n\n{$summary}\n\nBe concise and specific."; + $totalClicks = $topLinks->sum('clicks_count'); + $linkCount = $topLinks->count(); + $summary = $topLinks->map(fn ($l) => "- {$l->slug} ({$l->clicks_count} clicks) → {$l->target_url}")->implode("\n"); + + $prompt = <<name} +Total links analysed: {$linkCount} | Total clicks: {$totalClicks} + +Top links: +{$summary} + +Provide 3–4 short, specific insights: +- Which link types or destinations perform best and why +- Patterns across target domains (e.g. social, docs, pricing pages) +- What the low-click links have in common and how to improve them +- One concrete next action for this workspace + +No generic marketing advice. Base every insight on the data above. Be direct, no fluff. +PROMPT; $result = app(AiService::class)->complete($prompt); diff --git a/resources/views/components/ui/button.blade.php b/resources/views/components/ui/button.blade.php index 63fd6ed..915c44d 100644 --- a/resources/views/components/ui/button.blade.php +++ b/resources/views/components/ui/button.blade.php @@ -25,8 +25,8 @@ $cls = $base . ' ' . ($variants[$variant] ?? $variants['primary']); {{ $slot->isNotEmpty() ? $slot : $label }} @if($action) - - + +