[ [ "parts" => [ ["text" => $systemInstruction . "\n\n" . $prompt] ] ] ], "generationConfig" => [ "temperature" => 0.7, // A bit of creativity for varied responses "maxOutputTokens" => 150 ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200) { $result = json_decode($response, true); if (isset($result['candidates'][0]['content']['parts'][0]['text'])) { return trim($result['candidates'][0]['content']['parts'][0]['text']); } } return "والله يا صاحبي جربت تطبيق سيرو وارتحت كثير من المشاكل هذي، جربه ما بتندم."; // Fallback response } // Example usage if called directly via CLI: if (php_sapi_name() === 'cli') { echo "Testing Gemini Generation...\n"; $testContext = "التطبيقات الثانية بتاخذ عمولة عالية جداً ومش ملحقين بنزين!"; $generated = generateCommentWithGemini($testContext, 'promote_siro'); echo "Generated Comment: \n" . $generated . "\n"; }