Day 7 – Improving GPT Recommendations Using Click Feedback #LaravelGPT #AIRecommendations #FeedbackLoop #Personalization #OpenAI #LaravelAI


Today we’ll close the loop: using click data to help GPT make smarter, more personalized product recommendations based on what users actually engage with.


🧠 Step 1: Modify ProductRecommendationService to include click trends

Update your recommend() method to include clicked product info:

$clickedProducts = $user->productClicks()
    ->with('product')
    ->latest('clicked_at')
    ->take(5)
    ->get()
    ->pluck('product')
    ->filter()
    ->map(fn ($p) => [
        'name' => $p->name,
        'description' => $p->description,
        'category' => $p->category,
    ])
    ->toArray();

πŸ“‘ Step 2: Enhance GPT prompt with clicks

Modify the prompt inside recommend():

$viewed = ... // same as before
$clicked = $clickedProducts;

$messages = [
    [
        'role' => 'user',
        'content' => 'Here is what the user viewed: ' . json_encode($viewed)
    ],
    [
        'role' => 'user',
        'content' => 'Here is what the user clicked: ' . json_encode($clicked)
    ],
    [
        'role' => 'user',
        'content' => 'Suggest 5 relevant product ideas based on both viewing and clicking behavior.'
    ],
];

Call GPT as before, using the same function-calling structure.


πŸ§ͺ Optional: Add Click Weighting (Advanced)

You could improve further by:

  • Giving more importance to clicked products
  • Tracking click frequency and recency
  • Segmenting user interest profiles

But for now, just adding click data into the prompt helps GPT tailor results better.


βœ… Summary

βœ… Today you:

  • Pulled the user’s most-clicked products
  • Used that feedback to enrich GPT prompts
  • Moved from static to adaptive, personalized suggestions

βœ… Up next (Day 8): We’ll cache GPT responses to reduce API calls and boost performance, while keeping results fresh.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.