From 074c08fc6f95ff19d7a98fcfb4c41cead712506b Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sat, 29 Aug 2026 01:26:25 +0300 Subject: [PATCH] feat: Add AiLessonEnhancerService to automatically generate NotebookLM-style cheat sheets and quizzes --- .../app/Services/AiLessonEnhancerService.php | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 backend/app/Services/AiLessonEnhancerService.php diff --git a/backend/app/Services/AiLessonEnhancerService.php b/backend/app/Services/AiLessonEnhancerService.php new file mode 100644 index 0000000..48f92da --- /dev/null +++ b/backend/app/Services/AiLessonEnhancerService.php @@ -0,0 +1,102 @@ + [['parts' => [['text' => $prompt]]]], + 'generationConfig' => ['responseMimeType' => 'application/json', 'temperature' => 0.7] + ]; + + $ch = curl_init($url); + curl_setopt_array($ch, [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => json_encode($payload), + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 60 + ]); + $res = curl_exec($ch); + curl_close($ch); + + if (!$res) return null; + + $json = json_decode($res, true); + $text = $json['candidates'][0]['content']['parts'][0]['text'] ?? ''; + + $text = preg_replace('/^```json\s*/i', '', $text); + $text = preg_replace('/```\s*$/i', '', $text); + + return json_decode(trim($text), true); + } +}